SAS reads any input file (ASCII) separated by delimited characters. However, it is important to assign the format to the SAS variables to ensure that the columns are read correctly.
The following are to be established to ensure correct reading of the files.
- DLM -> ‘,’ OR ‘|’ or any other characters used as delimiter.
- DSD -> indicates that the data is sensitive and may contain delimiters between the quotes (string data) and need to be considered as characters.
- TRUNCOVER -> Assign the value to the variable even if the value is less than the allocate format size.
- LRECL -> default logical record length for reading an external file
- FIRSTOBS -> read from specified row number
- FORMAT -> :$20.
The most important is the : . The colon indicates that the reading of columns begin with the delimiter and must not consider the length (20 in this case) to separate the columnar data. $ is to indicate that it is a character. ($w.) w is the width of the characters.
Following is an example:
INFILE ‘C:\path_to_dir\file_name.csv’ DSD DLM=’,’ TRUNCOVER LRECL=1024 FIRSTOBS=2;
INPUT char_variable1 :$20. char_variable2:$20. char_variable3:$20. int_variable 5.3;