SlideShare a Scribd company logo
SASTechies [email_address] http://www.sastechies.com
Character data  with specified lengths Standard numeric data  values can only contain  numbers  decimal points  numbers in scientific, or E, notation (23E4)  minus signs.  Nonstandard numeric  data include  values that contain special characters, such as  percent signs (%), dollar signs ($), and commas (,)  date and time values  data in fraction, integer binary and real binary, and hexadecimal forms.  11/13/09 SAS Techies  2009
External File Data 11/13/09 SAS Techies  2009 Raw data can be organized in several different ways.  This external file contains data that is  free-format , meaning data that is not arranged in columns. Notice that the values for a particular field do not begin and end in the same columns. Column input can not be used to read data organized in this way. This external file contains data that is arranged in columns or  fixed fields . You can specify a beginning and ending column for each field. Let's look at how column input can be used to read this data. >----+----10---+----20   BARNES  NORTH  360.98  FARLSON  WEST  243.94  LAWRENCE  NORTH  195.04  NELSON  EAST  169.30  STEWART  SOUTH  238.45  TAYLOR  WEST  318.87  >----+----10---+----20    2810  61  MOD  F  2804  38  HIGH  F    2807  42  LOW  M    2816  26  HIGH  M  2833  32  MOD  F  2823  29  HIGH  M
Column Input   To use column input, your data  must  be standard character or numeric values in fixed fields.  input ID $ 1-4 Age 6-7 ActLevel $ 9-12 Sex $ 14;  One of the features of column input is the capability to read fields in any order. Character variables values can be up to 32K and can contain embedded blanks.  No placeholder is required for missing data. A blank field is read as missing and does not cause other fields to be read incorrectly.  Fields or parts of fields can be reread.  Fields do not have to be separated by blanks or other delimiters.  11/13/09 SAS Techies  2009 >----+----10---+----20    2810 61 MOD  F  2804 38 HIGH F   2807 42 LOW  M   2816 26 HIGH M  2833 32 MOD  F  2823 29 HIGH M
You can use  formatted input , which combines the features of column input with the ability to read nonstandard, as well as standard data.  Whenever you encounter raw data that is organized into fixed fields, you can use  column input to read standard data only  formatted input to read both standard and nonstandard data.  11/13/09 SAS Techies  2009
INPUT  pointer-control variable informat. ; The @ n  is an absolute pointer control that moves the input pointer to a specific column number.  you can use the @ n  to move a pointer forward or backward when reading a record.  The + n  is a relative pointer control that moves the input pointer forward to a column number relative to the current position.     input Name $14.  @16 Amount  comma6.2  damout var    input Name $14.  +2 Amount comma6.2   damout var 11/13/09 SAS Techies  2009 >----+----10---+----20---+--   ENVELOPE    $13.25   500   4   DISKETTES  $29.50   10    3   BANDS      $2.50    600   2   RIBBON      $94.20   12    1   PAPER        $15.95   250   10
The $ w . informat enables you to read character data.  The  w  represents the field width of the data value  or  the total number of columns that contain the raw data field.  input Name $14.  +2 Amount  input Name $ 1-14  +2 Amount  Difference !!! 11/13/09 SAS Techies  2009 >----+----10---+----20---+--   ENVELOPE   $13.25  500   4   DISKETTES   $29.50   10   3   BANDS      $2.50  600   2   RIBBON      $94.20   12   1   PAPER        $15.95  250  10
The informat for reading standard numeric data is the  w.d  informat.  11/13/09 SAS Techies  2009 34.0008      7.4      34.0008
The COMMA w.d  informat is used to read numeric values and remove embedded  blanks  commas  dashes  dollar signs  percent signs  right parentheses  left parentheses, which are converted to minus signs.   11/13/09 SAS Techies  2009 $34,000      Comma7.      34000
External files with a fixed-length record format have an end-of-record marker after a predetermined number of columns. A typical record length is 80 columns. 11/13/09 SAS Techies  2009 >----+----10---+----20---+---------------   BIRD FEEDER     LG088     3  20  GLASS MUGS      SB082     6  12  GLASS TRAY      BQ049   12   6  PADDED HANGRS  MN256  15  20  JEWELRY BOX    AJ498   23   0  RED APRON       AQ072   9  12  CRYSTAL VASE    AQ672   27    0  PICNIC BASKET  LS930   21    0
Beware of Errors infile receipts  pad ;  Files with a variable-length record format have an imaginary end-of-record marker after the last field in each record. 11/13/09 SAS Techies  2009 input Department $ 1-11 @13  TotalReceipts  comma8. ;  >----+----10---+--- V 20-------------   BED/BATH      1,354.93*   HOUSEWARES    2,464.05*   GARDEN         923.34*    GRILL        598.34*   SHOES         1,345.82*   SPORTS*   TOYS         6,536.53*
raw data that is  free-format ; that is, it is not arranged in fixed fields  The fields may be separated by blanks or some other delimiter  infile credit dlm=‘ ‘;  input Gender $ Age Bankcard FreqBank  Deptcard FreqDept;  11/13/09 SAS Techies  2009 >----+----10---+----20---+----    ABRAMS * L. * MARKETING * $8,209  BARCLAY * M. * MARKETING * $8,435  COURTNEY * W. * MARKETING * $9,006  FARLEY * J. * PUBLICATIONS * $8,305  HEINS * W. * PUBLICATIONS * $9,539  > V ---+----10---+----20   MALE 27 1 8 0 0   FEMALE 29 3 14 5 10   FEMALE 34 2 10 3 3
Limitations Missing data values must be specified with a period (.) for both character and numeric data. Although the width of a field can be greater than eight characters, both character and numeric variables have a default length of 8.  Character values longer than eight characters will be truncated. Data must be in standard numeric or character format. Character values cannot contain embedded blanks.  11/13/09 SAS Techies  2009
Missover option is used to handle missing values at the end of a record  If the missing value is in the middle of the record then edit the raw data file data perm.survey; infile credit  missover ;  input Gender $ Age Bankcard FreqBank Deptcard FreqDept;  11/13/09 SAS Techies  2009 > V ---+----10---+----20   MALE 27 1 8 92 39   FEMALE  *   3 14 5 10   FEMALE 34 2 10 3 3  > V ---+----10---+----20   MALE 27 1 8  *  *  FEMALE 29 3 14 5 10   FEMALE 34 2 10 3 3
You can make list input more versatile by using  modified  list input. There are two modifiers that can be used with list input. The ampersand ( & ) modifier is used to read character values that contain embedded blanks. The colon ( : ) modifier is used to read nonstandard data values and character values longer than eight characters, but without embedded blanks.  11/13/09 SAS Techies  2009 data perm.cityrank; infile topten;  input   Rank City & $12.  Pop86 : comma.;   >----+----10---+----20---+--    1  NEW YORK   7,262,700    2  LOS ANGELES   3,259,340    3 CHICAGO  3,009,530    4 HOUSTON  1,728,910    5  PHILADELPHIA   1,642,900    6 DETROIT  1,086,220    7  SAN DIEGO   1,015,190    8 DALLAS  1,003,520    9  SAN ANTONIO   914,350   10 PHOENIX  894,070
When you read a date using a SAS informat, SAS software converts it to a numeric  date value . A SAS date value is the number of days from January 1, 1960, to the given date. 11/13/09 SAS Techies  2009 Date Expression    SAS Date Informat    SAS Date Value 02Jan00 DATE w . 14611 01-02-2000 MMDDYY w . 14611 02/01/00 DDMMYY w . 14611 2000/01/02 YYMMDD w . 14611
SAS software stores  time values  similar to the way it stores date values. A SAS time value is stored as the number of seconds since midnight. A SAS  datetime  is a special value that combines both date and time information. A SAS datetime value is stored as the number of seconds between midnight on January 1, 1960, and a given date and time. 11/13/09 SAS Techies  2009
Date7. Informat Mmddyyn8. When a two-digit year value is read, SAS software defaults to a year within a 100-year span determined by the  YEARCUTOFF=  system option.  The value of the YEARCUTOFF= system option only affects  two-digit year values . A date value that contains a four-digit year value will be interpreted correctly even if it does not fall within the 100-year span set by the YEARCUTOFF= system option.  11/13/09 SAS Techies  2009 Date Expression Interpreted As 12/07/41 18Dec15 04/15/30 15Apr95 12/07/1941 18Dec2015 04/15/1930 15Apr1995
Since dates are stored as numerics any meaningful arithmetic calculations can be performed on them. Ex: Days=dateout-datein+1;  11/13/09 SAS Techies  2009
You use the  forward slash (/) line pointer control  to read multiple records in sequential order.  input  Lname $ 1-8 Fname $ 10-15  /  Department $ 1-12 JobCode $ 15-19  /  Salary comma10.;  Write  multiple Input  statements input Lname $ 1-8 Fname $ 10-15;   input Department $ 1-12 JobCode  $ 15-19;  input Salary comma10.;   one INPUT statement that contains a  line pointer control  to specify the record(s) from which values are to be read  input #1 Lname $ 1-8 Fname $ 10-15  #2 Department $ 1-12 JobCode $  #3 Salary comma10.;  11/13/09 SAS Techies  2009 >----+----10---+----   ABRAMS THOMAS MARKETING     SR01 $25,209.03  BARCLAY ROBERT  EDUCATION     IN01 $24,435.71  COURTNEY MARK PUBLICATIONS  TW01 $24,006.16
repeating blocks  of data that represent separate observations  an ID field followed by an  equal number  of repeating fields that represent separate observations  an ID field followed by a  varying number  of repeating fields that represent separate observations.    001 WALKING AEROBICS CYCLING   002 SWIMMING CYCLING SKIING   003 TENNIS SWIMMING AEROBICS 11/13/09 SAS Techies  2009 >----+----10---+----20---+----30-- 01APR90 68 02APR90 67 03APR90 78 04APR90 74 05APR90 72 06APR90 73 07APR90 71 08APR90 75 09APR90 76 >----+----10---+----20---+----30-- >----+----10---+----20---+----30--   001 WALKING   002 SWIMMING CYCLING SKIING   003 TENNIS SWIMMING
The SAS System provides two line-hold specifiers.  The trailing @ enables the  next INPUT statement  to read from the current record in the  same iteration  of the DATA step.  Ex: input name $20. @;  The double trailing at sign (@@) enables the  next INPUT statement  to read from the current record  across  further  iterations  of the DATA step.  input name $20. @@; 11/13/09 SAS Techies  2009
input ID $4. @@;   .   . input Department 5.;  Normally, each time a DATA step executes, the INPUT statement reads a new record. But when you use the @@, the INPUT statement holds the current record and reads the next value. A record held by the double trailing at sign (@@) is not released until the input pointer moves past the end of the record. Then the input pointer moves down to the next record.  an INPUT statement without a line-hold specifier executes.  11/13/09 SAS Techies  2009
data perm.april90;  infile tempdata;  input Date : date. HighTemp @@;  format date date7.;  run;  11/13/09 SAS Techies  2009
Like the @@, the single trailing @  enables the next INPUT statement to read from the same record  releases the current record when a subsequent INPUT statement executes without a line-hold specifier.  Unlike the @@, the single @ also releases a record when control returns to the top of the DATA step for the next iteration. 11/13/09 SAS Techies  2009
data perm.sales97; infile data97; input ID $4. @; do Quarter=1 to 4;  input Sales : comma. @;  output; end; run;  11/13/09 SAS Techies  2009
H  indicates a  header record  that contains a street address and  P  indicates a  detail record  that contains information about a person living at that address.  Raw Data File  SAS Data Set  11/13/09 SAS Techies  2009 >----+----10---+----   HP P P HP P P P P H   321 S. MAIN ST   MARY E    21 F   WILLIAM M 23 M   SUSAN K    3 F   324 S. MAIN ST   THOMAS H  79 M   WALTER S  46 M   ALICE A   42 F   MARYANN A 20 F   JOHN S    16 M   325A S. MAIN ST Obs  Address          Name       Age Gender   1   321 S. MAIN ST   MARY E     21    F   2   321 S. MAIN ST   WILLIAM M  23    M   3   321 S. MAIN ST   SUSAN K     3    F   4   324 S. MAIN ST   THOMAS H   79    M   5   324 S. MAIN ST   WALTER S   46    M   6   324 S. MAIN ST   ALICE A    42    F   7   324 S. MAIN ST   MARYANN A  20    F   8   324 S. MAIN ST   JOHN S     16    M   9   325A S. MAIN ST  JAMES L    34    M  10  325A S. MAIN ST  LIZA A     31    F  11  325B S. MAIN ST  MARGO K    27    F
you want to  keep the header record  as a part of each observation until the next header record is encountered.  RETAIN   variable1 variable2 ; If no variable is mentioned then applies to ALL variables. When a RETAIN statement specifies variables, new variables are created. Therefore, you must name any variables used in a RETAIN statement exactly as you want them stored in the data set. You might need to drop the extra variables. 11/13/09 SAS Techies  2009 data perm.people;   infile census; retain Address;  >----+----10---+----   H   321 S. MAIN ST   P  P  P MARY E      21 F WILLIAM M 23 M SUSAN K     3  F
data perm.people  (drop=type) ; infile census;  retain Address;  input type $1. @; if type='H' then input @3 Address $15 @@.; if type='P‘ then input @3 Name $10. @13 Age 3. @15 Gender $1.; run;  11/13/09 SAS Techies  2009
Raw Data File  SAS Data Set  11/13/09 SAS Techies  2009 >----+----10---+---20   H 321 S. MAIN ST   P MARY E     21 F  P WILLIAM M 23 M  P SUSAN K    3  F  H 324 S. MAIN ST  P THOMAS H  79 M  P WALTER S  46 M  P ALICE A   42 F  P MARYANN A 20 F  P JOHN S    16 M  H 325A S. MAIN ST P JAMES L 34 M P LIZA A 31 F H 325B S. MAIN ST P MARGO K 27 F  P  WILLIAM R 27 M  P ROBERT W 1 M Address  321 S. MAIN ST  324 S. MAIN ST 325A S. MAIN ST 325B S. MAIN ST  Total 3 5 2 3
data perm.phones; infile phondat  length=reclen;  input ID 4. @;  namelen=reclen-9; input Name  $varying10.  namelen   PhoneExt;  it's important to specify a  w  value  that is large enough to accommodate the longest value.  11/13/09 SAS Techies  2009 >----+----10--- V ----20 1802 JOHNSON 2123   1803 1804 1805 1806 1807 1808 1809 BARKER2142 EDMUNDSON2325 RIVERS2543 MASON2646 JACKSON2049 LEVY2856 THOMAS2222
data perm.health; infile bpdata length=reclen;  input ID 4. @; do  index=6 to reclen by 15;   input Date : date. BP $ @;   output; end;   run;  11/13/09 SAS Techies  2009                                   15             15             15         |     14     | |     14     | |     14     | >----+----10---+---- V 0---+----30--- V ----40---+---- V 0   1234 13MAR89 120/80 1443 12FEB89 120/70 03FEB90 125/80 07OCT90 125/99 1681 11JAN90 120/80 05JUN90 110/70 2034 19NOV88 130/70 12MAY89 150/90 23MAR90 130/80

More Related Content

PPT
SAS Proc SQL
PPT
Sas Plots Graphs
PPT
Utility Procedures in SAS
PPT
SAS Functions
PPT
SAS Macros
PPT
SAS Access / SAS Connect
PPT
Improving Effeciency with Options in SAS
PPT
SAS ODS HTML
SAS Proc SQL
Sas Plots Graphs
Utility Procedures in SAS
SAS Functions
SAS Macros
SAS Access / SAS Connect
Improving Effeciency with Options in SAS
SAS ODS HTML

What's hot (20)

PDF
Sas cheat
PDF
Proc sql tips
PDF
SAS cheat sheet
PPT
Data Match Merging in SAS
PPT
Understanding SAS Data Step Processing
PPT
Base SAS Statistics Procedures
PPTX
Proc SQL in SAS Enterprise Guide 4.3
PDF
Sas® Macro Design Patterns
PPTX
Understanding sas data step processing.
PPT
ABAP Programming Overview
PPT
SAS Macros part 1
PDF
Sas Talk To R Users Group
PPTX
Sap abap-data structures and internal tables
PDF
PPTX
Sap abap
PDF
Sap abap tutorial 1 (1)
PPT
Oracle tips and tricks
PDF
05 internal tables
DOCX
Internal tables
PPT
Internal tables
Sas cheat
Proc sql tips
SAS cheat sheet
Data Match Merging in SAS
Understanding SAS Data Step Processing
Base SAS Statistics Procedures
Proc SQL in SAS Enterprise Guide 4.3
Sas® Macro Design Patterns
Understanding sas data step processing.
ABAP Programming Overview
SAS Macros part 1
Sas Talk To R Users Group
Sap abap-data structures and internal tables
Sap abap
Sap abap tutorial 1 (1)
Oracle tips and tricks
05 internal tables
Internal tables
Internal tables
Ad

Similar to Reading Fixed And Varying Data (20)

PPT
May Woo Bi Portfolio
PPT
Select To Order By
PDF
SAS Internal Training
PPTX
Beginers guide for oracle sql
PPT
Basics Of SAS Programming Language
PPTX
SAS Mainframe -Program-Tips
PPT
R Text-Based Data I/O and Data Frame Access and Manupulation
PPT
Marc format
DOCX
Sas practice programs
PPT
Sas classes in mumbai
PDF
Sq lite functions
PDF
PL/SQL and radix tree structure
DOCX
Pumps, Compressors and Turbine Fault Frequency Analysis
PDF
Pumps, Compressors and Turbine Fault Frequency Analysis
PPT
Prog1 chap1 and chap 2
PPTX
SQL python for beginners easy explanation with concepts and output .pptx
PPTX
Keyboard interrupt
PDF
Cassandra, web scale no sql data platform
May Woo Bi Portfolio
Select To Order By
SAS Internal Training
Beginers guide for oracle sql
Basics Of SAS Programming Language
SAS Mainframe -Program-Tips
R Text-Based Data I/O and Data Frame Access and Manupulation
Marc format
Sas practice programs
Sas classes in mumbai
Sq lite functions
PL/SQL and radix tree structure
Pumps, Compressors and Turbine Fault Frequency Analysis
Pumps, Compressors and Turbine Fault Frequency Analysis
Prog1 chap1 and chap 2
SQL python for beginners easy explanation with concepts and output .pptx
Keyboard interrupt
Cassandra, web scale no sql data platform
Ad

Recently uploaded (20)

PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPT
Teaching material agriculture food technology
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
cuic standard and advanced reporting.pdf
PPTX
Spectroscopy.pptx food analysis technology
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Encapsulation theory and applications.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Cloud computing and distributed systems.
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Reach Out and Touch Someone: Haptics and Empathic Computing
Teaching material agriculture food technology
Dropbox Q2 2025 Financial Results & Investor Presentation
Building Integrated photovoltaic BIPV_UPV.pdf
Spectral efficient network and resource selection model in 5G networks
Agricultural_Statistics_at_a_Glance_2022_0.pdf
cuic standard and advanced reporting.pdf
Spectroscopy.pptx food analysis technology
20250228 LYD VKU AI Blended-Learning.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Programs and apps: productivity, graphics, security and other tools
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Encapsulation theory and applications.pdf
Approach and Philosophy of On baking technology
Machine learning based COVID-19 study performance prediction
Cloud computing and distributed systems.
The Rise and Fall of 3GPP – Time for a Sabbatical?
Network Security Unit 5.pdf for BCA BBA.
Per capita expenditure prediction using model stacking based on satellite ima...

Reading Fixed And Varying Data

  • 2. Character data with specified lengths Standard numeric data values can only contain numbers decimal points numbers in scientific, or E, notation (23E4) minus signs. Nonstandard numeric data include values that contain special characters, such as percent signs (%), dollar signs ($), and commas (,) date and time values data in fraction, integer binary and real binary, and hexadecimal forms. 11/13/09 SAS Techies 2009
  • 3. External File Data 11/13/09 SAS Techies 2009 Raw data can be organized in several different ways. This external file contains data that is free-format , meaning data that is not arranged in columns. Notice that the values for a particular field do not begin and end in the same columns. Column input can not be used to read data organized in this way. This external file contains data that is arranged in columns or fixed fields . You can specify a beginning and ending column for each field. Let's look at how column input can be used to read this data. >----+----10---+----20   BARNES NORTH 360.98  FARLSON WEST 243.94  LAWRENCE NORTH 195.04  NELSON EAST 169.30  STEWART SOUTH 238.45  TAYLOR WEST 318.87 >----+----10---+----20   2810 61 MOD F  2804 38 HIGH F  2807 42 LOW M  2816 26 HIGH M  2833 32 MOD F  2823 29 HIGH M
  • 4. Column Input To use column input, your data must be standard character or numeric values in fixed fields. input ID $ 1-4 Age 6-7 ActLevel $ 9-12 Sex $ 14; One of the features of column input is the capability to read fields in any order. Character variables values can be up to 32K and can contain embedded blanks. No placeholder is required for missing data. A blank field is read as missing and does not cause other fields to be read incorrectly. Fields or parts of fields can be reread. Fields do not have to be separated by blanks or other delimiters. 11/13/09 SAS Techies 2009 >----+----10---+----20   2810 61 MOD  F  2804 38 HIGH F  2807 42 LOW  M  2816 26 HIGH M  2833 32 MOD  F  2823 29 HIGH M
  • 5. You can use formatted input , which combines the features of column input with the ability to read nonstandard, as well as standard data. Whenever you encounter raw data that is organized into fixed fields, you can use column input to read standard data only formatted input to read both standard and nonstandard data. 11/13/09 SAS Techies 2009
  • 6. INPUT pointer-control variable informat. ; The @ n is an absolute pointer control that moves the input pointer to a specific column number. you can use the @ n to move a pointer forward or backward when reading a record. The + n is a relative pointer control that moves the input pointer forward to a column number relative to the current position.   input Name $14. @16 Amount comma6.2 damout var   input Name $14. +2 Amount comma6.2 damout var 11/13/09 SAS Techies 2009 >----+----10---+----20---+--   ENVELOPE   $13.25   500   4  DISKETTES $29.50   10   3  BANDS     $2.50   600   2  RIBBON     $94.20   12   1  PAPER       $15.95   250   10
  • 7. The $ w . informat enables you to read character data. The w represents the field width of the data value or the total number of columns that contain the raw data field. input Name $14. +2 Amount input Name $ 1-14 +2 Amount Difference !!! 11/13/09 SAS Techies 2009 >----+----10---+----20---+--   ENVELOPE   $13.25  500   4  DISKETTES  $29.50   10   3  BANDS     $2.50  600   2  RIBBON     $94.20   12   1  PAPER       $15.95  250  10
  • 8. The informat for reading standard numeric data is the w.d informat. 11/13/09 SAS Techies 2009 34.0008      7.4      34.0008
  • 9. The COMMA w.d informat is used to read numeric values and remove embedded blanks commas dashes dollar signs percent signs right parentheses left parentheses, which are converted to minus signs. 11/13/09 SAS Techies 2009 $34,000      Comma7.      34000
  • 10. External files with a fixed-length record format have an end-of-record marker after a predetermined number of columns. A typical record length is 80 columns. 11/13/09 SAS Techies 2009 >----+----10---+----20---+---------------   BIRD FEEDER   LG088   3 20  GLASS MUGS     SB082   6 12  GLASS TRAY     BQ049 12 6  PADDED HANGRS MN256 15 20  JEWELRY BOX   AJ498 23  0  RED APRON     AQ072 9 12  CRYSTAL VASE   AQ672 27   0  PICNIC BASKET LS930 21   0
  • 11. Beware of Errors infile receipts pad ; Files with a variable-length record format have an imaginary end-of-record marker after the last field in each record. 11/13/09 SAS Techies 2009 input Department $ 1-11 @13 TotalReceipts comma8. ; >----+----10---+--- V 20-------------   BED/BATH     1,354.93*  HOUSEWARES   2,464.05*  GARDEN       923.34*  GRILL       598.34*  SHOES       1,345.82*  SPORTS*  TOYS        6,536.53*
  • 12. raw data that is free-format ; that is, it is not arranged in fixed fields The fields may be separated by blanks or some other delimiter infile credit dlm=‘ ‘; input Gender $ Age Bankcard FreqBank Deptcard FreqDept; 11/13/09 SAS Techies 2009 >----+----10---+----20---+----   ABRAMS * L. * MARKETING * $8,209  BARCLAY * M. * MARKETING * $8,435  COURTNEY * W. * MARKETING * $9,006  FARLEY * J. * PUBLICATIONS * $8,305  HEINS * W. * PUBLICATIONS * $9,539 > V ---+----10---+----20   MALE 27 1 8 0 0  FEMALE 29 3 14 5 10  FEMALE 34 2 10 3 3
  • 13. Limitations Missing data values must be specified with a period (.) for both character and numeric data. Although the width of a field can be greater than eight characters, both character and numeric variables have a default length of 8. Character values longer than eight characters will be truncated. Data must be in standard numeric or character format. Character values cannot contain embedded blanks. 11/13/09 SAS Techies 2009
  • 14. Missover option is used to handle missing values at the end of a record If the missing value is in the middle of the record then edit the raw data file data perm.survey; infile credit missover ; input Gender $ Age Bankcard FreqBank Deptcard FreqDept; 11/13/09 SAS Techies 2009 > V ---+----10---+----20   MALE 27 1 8 92 39   FEMALE * 3 14 5 10  FEMALE 34 2 10 3 3 > V ---+----10---+----20   MALE 27 1 8 * *  FEMALE 29 3 14 5 10  FEMALE 34 2 10 3 3
  • 15. You can make list input more versatile by using modified list input. There are two modifiers that can be used with list input. The ampersand ( & ) modifier is used to read character values that contain embedded blanks. The colon ( : ) modifier is used to read nonstandard data values and character values longer than eight characters, but without embedded blanks. 11/13/09 SAS Techies 2009 data perm.cityrank; infile topten; input Rank City & $12. Pop86 : comma.; >----+----10---+----20---+--   1 NEW YORK  7,262,700   2 LOS ANGELES   3,259,340   3 CHICAGO  3,009,530   4 HOUSTON  1,728,910   5 PHILADELPHIA  1,642,900   6 DETROIT  1,086,220   7 SAN DIEGO  1,015,190   8 DALLAS  1,003,520   9 SAN ANTONIO  914,350  10 PHOENIX  894,070
  • 16. When you read a date using a SAS informat, SAS software converts it to a numeric date value . A SAS date value is the number of days from January 1, 1960, to the given date. 11/13/09 SAS Techies 2009 Date Expression    SAS Date Informat    SAS Date Value 02Jan00 DATE w . 14611 01-02-2000 MMDDYY w . 14611 02/01/00 DDMMYY w . 14611 2000/01/02 YYMMDD w . 14611
  • 17. SAS software stores time values similar to the way it stores date values. A SAS time value is stored as the number of seconds since midnight. A SAS datetime is a special value that combines both date and time information. A SAS datetime value is stored as the number of seconds between midnight on January 1, 1960, and a given date and time. 11/13/09 SAS Techies 2009
  • 18. Date7. Informat Mmddyyn8. When a two-digit year value is read, SAS software defaults to a year within a 100-year span determined by the YEARCUTOFF= system option. The value of the YEARCUTOFF= system option only affects two-digit year values . A date value that contains a four-digit year value will be interpreted correctly even if it does not fall within the 100-year span set by the YEARCUTOFF= system option. 11/13/09 SAS Techies 2009 Date Expression Interpreted As 12/07/41 18Dec15 04/15/30 15Apr95 12/07/1941 18Dec2015 04/15/1930 15Apr1995
  • 19. Since dates are stored as numerics any meaningful arithmetic calculations can be performed on them. Ex: Days=dateout-datein+1; 11/13/09 SAS Techies 2009
  • 20. You use the forward slash (/) line pointer control to read multiple records in sequential order. input Lname $ 1-8 Fname $ 10-15 / Department $ 1-12 JobCode $ 15-19 / Salary comma10.; Write multiple Input statements input Lname $ 1-8 Fname $ 10-15; input Department $ 1-12 JobCode $ 15-19; input Salary comma10.; one INPUT statement that contains a line pointer control to specify the record(s) from which values are to be read input #1 Lname $ 1-8 Fname $ 10-15 #2 Department $ 1-12 JobCode $ #3 Salary comma10.; 11/13/09 SAS Techies 2009 >----+----10---+----   ABRAMS THOMAS MARKETING     SR01 $25,209.03 BARCLAY ROBERT EDUCATION     IN01 $24,435.71 COURTNEY MARK PUBLICATIONS  TW01 $24,006.16
  • 21. repeating blocks of data that represent separate observations an ID field followed by an equal number of repeating fields that represent separate observations an ID field followed by a varying number of repeating fields that represent separate observations.   001 WALKING AEROBICS CYCLING   002 SWIMMING CYCLING SKIING   003 TENNIS SWIMMING AEROBICS 11/13/09 SAS Techies 2009 >----+----10---+----20---+----30-- 01APR90 68 02APR90 67 03APR90 78 04APR90 74 05APR90 72 06APR90 73 07APR90 71 08APR90 75 09APR90 76 >----+----10---+----20---+----30-- >----+----10---+----20---+----30--   001 WALKING   002 SWIMMING CYCLING SKIING   003 TENNIS SWIMMING
  • 22. The SAS System provides two line-hold specifiers. The trailing @ enables the next INPUT statement to read from the current record in the same iteration of the DATA step. Ex: input name $20. @; The double trailing at sign (@@) enables the next INPUT statement to read from the current record across further iterations of the DATA step. input name $20. @@; 11/13/09 SAS Techies 2009
  • 23. input ID $4. @@; . . input Department 5.; Normally, each time a DATA step executes, the INPUT statement reads a new record. But when you use the @@, the INPUT statement holds the current record and reads the next value. A record held by the double trailing at sign (@@) is not released until the input pointer moves past the end of the record. Then the input pointer moves down to the next record. an INPUT statement without a line-hold specifier executes. 11/13/09 SAS Techies 2009
  • 24. data perm.april90; infile tempdata; input Date : date. HighTemp @@; format date date7.; run; 11/13/09 SAS Techies 2009
  • 25. Like the @@, the single trailing @ enables the next INPUT statement to read from the same record releases the current record when a subsequent INPUT statement executes without a line-hold specifier. Unlike the @@, the single @ also releases a record when control returns to the top of the DATA step for the next iteration. 11/13/09 SAS Techies 2009
  • 26. data perm.sales97; infile data97; input ID $4. @; do Quarter=1 to 4; input Sales : comma. @; output; end; run; 11/13/09 SAS Techies 2009
  • 27. H indicates a header record that contains a street address and P indicates a detail record that contains information about a person living at that address. Raw Data File SAS Data Set 11/13/09 SAS Techies 2009 >----+----10---+----   HP P P HP P P P P H   321 S. MAIN ST  MARY E    21 F  WILLIAM M 23 M  SUSAN K    3 F  324 S. MAIN ST  THOMAS H  79 M  WALTER S  46 M  ALICE A   42 F  MARYANN A 20 F  JOHN S    16 M  325A S. MAIN ST Obs  Address          Name       Age Gender  1   321 S. MAIN ST   MARY E     21    F  2   321 S. MAIN ST   WILLIAM M  23    M  3   321 S. MAIN ST   SUSAN K     3    F  4   324 S. MAIN ST   THOMAS H   79    M  5   324 S. MAIN ST   WALTER S   46    M  6   324 S. MAIN ST   ALICE A    42    F  7   324 S. MAIN ST   MARYANN A  20    F  8   324 S. MAIN ST   JOHN S     16    M  9   325A S. MAIN ST  JAMES L    34    M 10  325A S. MAIN ST  LIZA A     31    F 11  325B S. MAIN ST  MARGO K    27    F
  • 28. you want to keep the header record as a part of each observation until the next header record is encountered. RETAIN variable1 variable2 ; If no variable is mentioned then applies to ALL variables. When a RETAIN statement specifies variables, new variables are created. Therefore, you must name any variables used in a RETAIN statement exactly as you want them stored in the data set. You might need to drop the extra variables. 11/13/09 SAS Techies 2009 data perm.people; infile census; retain Address; >----+----10---+----   H   321 S. MAIN ST   P  P  P MARY E     21 F WILLIAM M 23 M SUSAN K     3 F
  • 29. data perm.people (drop=type) ; infile census; retain Address; input type $1. @; if type='H' then input @3 Address $15 @@.; if type='P‘ then input @3 Name $10. @13 Age 3. @15 Gender $1.; run; 11/13/09 SAS Techies 2009
  • 30. Raw Data File SAS Data Set 11/13/09 SAS Techies 2009 >----+----10---+---20   H 321 S. MAIN ST P MARY E    21 F P WILLIAM M 23 M P SUSAN K    3 F H 324 S. MAIN ST P THOMAS H  79 M P WALTER S  46 M P ALICE A   42 F P MARYANN A 20 F P JOHN S    16 M H 325A S. MAIN ST P JAMES L 34 M P LIZA A 31 F H 325B S. MAIN ST P MARGO K 27 F P WILLIAM R 27 M P ROBERT W 1 M Address 321 S. MAIN ST 324 S. MAIN ST 325A S. MAIN ST 325B S. MAIN ST Total 3 5 2 3
  • 31. data perm.phones; infile phondat length=reclen; input ID 4. @; namelen=reclen-9; input Name $varying10. namelen PhoneExt; it's important to specify a w value that is large enough to accommodate the longest value. 11/13/09 SAS Techies 2009 >----+----10--- V ----20 1802 JOHNSON 2123   1803 1804 1805 1806 1807 1808 1809 BARKER2142 EDMUNDSON2325 RIVERS2543 MASON2646 JACKSON2049 LEVY2856 THOMAS2222
  • 32. data perm.health; infile bpdata length=reclen; input ID 4. @; do index=6 to reclen by 15; input Date : date. BP $ @; output; end; run; 11/13/09 SAS Techies 2009                                   15             15             15         |     14     | |     14     | |     14     | >----+----10---+---- V 0---+----30--- V ----40---+---- V 0   1234 13MAR89 120/80 1443 12FEB89 120/70 03FEB90 125/80 07OCT90 125/99 1681 11JAN90 120/80 05JUN90 110/70 2034 19NOV88 130/70 12MAY89 150/90 23MAR90 130/80

Editor's Notes

  • #3: SASTechies.com Sharad C Narnindi - Attic Technologies 2005
  • #4: SASTechies.com Sharad C Narnindi - Attic Technologies 2005
  • #5: SASTechies.com Sharad C Narnindi - Attic Technologies 2005
  • #6: SASTechies.com Sharad C Narnindi - Attic Technologies 2005
  • #7: SASTechies.com Sharad C Narnindi - Attic Technologies 2005
  • #8: SASTechies.com Sharad C Narnindi - Attic Technologies 2005
  • #9: SASTechies.com Sharad C Narnindi - Attic Technologies 2005
  • #10: SASTechies.com Sharad C Narnindi - Attic Technologies 2005
  • #11: SASTechies.com Sharad C Narnindi - Attic Technologies 2005
  • #12: SASTechies.com Sharad C Narnindi - Attic Technologies 2005
  • #13: SASTechies.com Sharad C Narnindi - Attic Technologies 2005
  • #14: SASTechies.com Sharad C Narnindi - Attic Technologies 2005
  • #15: SASTechies.com Sharad C Narnindi - Attic Technologies 2005
  • #16: SASTechies.com Sharad C Narnindi - Attic Technologies 2005
  • #17: SASTechies.com Sharad C Narnindi - Attic Technologies 2005
  • #18: SASTechies.com Sharad C Narnindi - Attic Technologies 2005
  • #19: SASTechies.com Sharad C Narnindi - Attic Technologies 2005
  • #20: SASTechies.com Sharad C Narnindi - Attic Technologies 2005
  • #21: SASTechies.com Sharad C Narnindi - Attic Technologies 2005
  • #22: SASTechies.com Sharad C Narnindi - Attic Technologies 2005
  • #23: SASTechies.com Sharad C Narnindi - Attic Technologies 2005
  • #24: SASTechies.com Sharad C Narnindi - Attic Technologies 2005
  • #25: SASTechies.com Sharad C Narnindi - Attic Technologies 2005
  • #26: SASTechies.com Sharad C Narnindi - Attic Technologies 2005
  • #27: SASTechies.com Sharad C Narnindi - Attic Technologies 2005
  • #28: SASTechies.com Sharad C Narnindi - Attic Technologies 2005
  • #29: SASTechies.com Sharad C Narnindi - Attic Technologies 2005
  • #30: SASTechies.com Sharad C Narnindi - Attic Technologies 2005
  • #31: SASTechies.com Sharad C Narnindi - Attic Technologies 2005
  • #32: SASTechies.com Sharad C Narnindi - Attic Technologies 2005
  • #33: SASTechies.com Sharad C Narnindi - Attic Technologies 2005