DATA Step, Macro, Functions and more

I did not understand how datalines are read in the following program

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

I did not understand how datalines are read in the following program

data nums;
    infile datalines dsd delimiter='ab';
    input X Y Z;
    datalines;
1aa2ab3
4b5bab6
7a8b9
;
run;



Output:
 The SAS System                        

                       OBS    X    Y    Z

                        1     1    .    2
                        2     4    5    .
                        3     7    8    9

Accepted Solutions
Solution
‎02-11-2016 04:57 AM
Super Contributor
Posts: 490

Re: I did not understand how datalines are read in the following program

[ Edited ]
Posted in reply to Jeevan007

In the DELIMITER= statement you specify list of individual delimiters, in this example you have two individual delimiters a and b.

 

The question now is, What if we have two or more consecutive delimiters? You have two cases for that:

 

1- DELIMITER= alone
Any combination of consecutive delimiter are treated as only one delimiter. So if you deleted the statment DSD in the infile statment from your example.

In the dataset example: 1aa2ab3

will be treated as: aa ab 3

as if 

1,2,3

 

2- DELIMITER= with DSD
Consecutive delimiters are treated individually even if they are consecutive.

In the dataset example: 1aa2ab3
will be treated as: 1 a Missing a 2 a Missing b 3
as if
1, , 2, , 3

View solution in original post


All Replies
Super Contributor
Posts: 490

Re: I did not understand how datalines are read in the following program

Posted in reply to Jeevan007

This example is explained here:

Example 1: Changing How Delimiters Are Treated

New Contributor
Posts: 3

Re: I did not understand how datalines are read in the following program

Posted in reply to mohamed_zaki

I have read that. I did not understand it.

Solution
‎02-11-2016 04:57 AM
Super Contributor
Posts: 490

Re: I did not understand how datalines are read in the following program

[ Edited ]
Posted in reply to Jeevan007

In the DELIMITER= statement you specify list of individual delimiters, in this example you have two individual delimiters a and b.

 

The question now is, What if we have two or more consecutive delimiters? You have two cases for that:

 

1- DELIMITER= alone
Any combination of consecutive delimiter are treated as only one delimiter. So if you deleted the statment DSD in the infile statment from your example.

In the dataset example: 1aa2ab3

will be treated as: aa ab 3

as if 

1,2,3

 

2- DELIMITER= with DSD
Consecutive delimiters are treated individually even if they are consecutive.

In the dataset example: 1aa2ab3
will be treated as: 1 a Missing a 2 a Missing b 3
as if
1, , 2, , 3

New Contributor
Posts: 3

Re: I did not understand how datalines are read in the following program

Posted in reply to mohamed_zaki

Thanks a lot!!

Super User
Posts: 19,868

Re: I did not understand how datalines are read in the following program

Posted in reply to Jeevan007

What part don't you understand? 

 

Things you should understand:

1. What are the delimiters?

2. What does the DSD option do?

 

Try the code with the above removed and variations on the DLM to help figure out what's going on. 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 252 views
  • 0 likes
  • 3 in conversation