Sample 24711: Reading comma delimited data with modified list input
Read in comma delimited data by specifying the DSD option
on the INFILE statement and using modified list-input style.
Note:
Modified list input uses format modifiers to help read in
data. For example, use the : modifier with an informat to
read character values that are longer than 8 bytes or vary
in length or numeric values that contain nonstandard values.
The DSD option on the INFILE statement has three benefits:
1) defaults to a comma delimiter, 2) strips quotes from text
strings, and 3) interprets consecutive delimiters as a
missing value.
Data files may require additional INFILE statement options.
If record lengths exceed 256 bytes, add the LRECL= option
on the INFILE statement to specify a larger record length.
Additionally, TRUNCOVER may need to be specified to prevent
SAS from reading more than one record at a time when reading
variable length data and/or missing values.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
/* Modified list input uses format modifiers to help read in data. */
/* For example, the : (colon) format modifier enables you to use list */
/* input to read data values that need the additional instructions */
/* that informats can provide but that are not aligned in columns. */
/* See the SAS Language Reference, Dictionary under INPUT Statement, */
/* List for more information. */
data grades;
infile datalines dsd;
input student :$20. test1-test4 fee :dollar8.;
datalines;
"Alexander,Bertrum",3.8,,,3.9,$500
"Chang,Daniel",,3.0,3.6,3.5,$400
"Elano,Fen",4.0,3.8,3.9,4.0,$300
;
proc print;
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
Obs student test1 test2 test3 test4 fee
1 Alexander,Bertrum 3.8 . . 3.9 500
2 Chang,Daniel . 3.0 3.6 3.5 400
3 Elano,Fen 4.0 3.8 3.9 4.0 300
Read in comma delimited data by specifying the DSD option on the INFILE statement and using modified list-input style.
Type: | Sample |
Topic: | SAS Reference ==> DATA Step Common Programming Tasks ==> Reading and Writing External Data
|
Date Modified: | 2019-06-11 14:59:58 |
Date Created: | 2004-09-30 14:09:07 |
Operating System and Release Information
SAS System | Base SAS | All | n/a | n/a |