If i have a code -
data test;
infile datalines ;
input a b c;
datalines;
1 2 3
4 5
6 7
;
I get two observations -
1 2 3
4 5 6
But if i use the code
data test;
infile datalines dsd dlm=' ';
input a b c ;
datalines;
1 2 3
4 5
6 7
;
Here it identifies all the spaces as missing values.
result is
1 2 3
. 4 5
6 7.
DSD identifies two delimiters as space where as in the code we have only one space before 4 and it is still identified as a delimiter and a missing value comes before 4. Why?
With dsd, each single delimiter character (blank since you did not specify another) is counted, so the second row in the datalines is considered as
<empty><blank>4<blank>5
and therefore supplies three values.
The third row is
6<blank>7<blank><emtpy>
and supplies another three values.
Without dsd, the leading blank in the second row is simply discarded, and the data step skips to a new line (reading 4/5/6 instead of ./4/5). Since it automatically skips to a new line at the end of the data step iteration (and no more lines are present), value 7 is never read and only 2 observations are output.
With dsd, each single delimiter character (blank since you did not specify another) is counted, so the second row in the datalines is considered as
<empty><blank>4<blank>5
and therefore supplies three values.
The third row is
6<blank>7<blank><emtpy>
and supplies another three values.
Without dsd, the leading blank in the second row is simply discarded, and the data step skips to a new line (reading 4/5/6 instead of ./4/5). Since it automatically skips to a new line at the end of the data step iteration (and no more lines are present), value 7 is never read and only 2 observations are output.
In second line you said the values are in this format
<empty><blank>4<blank>5
but isnt it in the below format because we have only one space before 4 and one space before 5.
<blank>4<blank>5
where did <empty> come from?
@riyaaora275 wrote:
In second line you said the values are in this format
<empty><blank>4<blank>5
but isnt it in the below format because we have only one space before 4 and one space before 5.
<blank>4<blank>5
where did <empty> come from?
Because of the dsd option, the data step assumes that there has to be a value before the first delimiter (blank). If there's nothing (consider it a string of length 0), then you have a missing value. Without dsd, leading delimiters are skipped until there's something.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.