Thursday, March 10, 2011

DLM and DSD options in infile statement and & usage

The DLM= option enables you to list read data with delimiters rather than the default space. i.e., if your data are separated by ";", you can use DLM=';' to read them correctly.

The DSD (Delimiter-Sensitive Data) in infile statement does three things for you. 1: it ignores delimiters in data values enclosed in quotation marks; 2: it ignores quotation marks as part of your data; 3: it treats two consecutive delimiters in a row as missing value.

eg1: we want to read this data set named testdata.txt in c:\sasdata.

10034 "apples, grapes kiwi" 123456
92626 "oranges" 97654
25414 "pears apple" 987654

data test;
      infile 'c:\sasdata\testdata.txt' dlm=' ' dsd;
      length name $22;
      input zip name $ pounds;


& usage in SAS

& stops reading character variables until it encounters two or more spaces. So a single space to differentiate the character variable and the adjacent variable will be ignored and the two variables will be treated as one variable.

data web;
input age site & $41. hits;
12   123456
30   97654
54    987654

data two;
input name & 20. age;
james band   25
barak obama   26
jintao hu   25

1 comment: