BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
riyaaora275
Obsidian | Level 7

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

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.

riyaaora275
Obsidian | Level 7

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?

Kurt_Bremser
Super User

@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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1227 views
  • 1 like
  • 2 in conversation