DATA Step, Macro, Functions and more

Can someone explain this code to me?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

Can someone explain this code to me?

[ Edited ]

The objective here is to output a raw data file. I know that Put and File are used to write raw data file. I am not sure here there is INFILE which is used to read data, cards, missover and  text and lrecl?

 

data _null_;
infile cards missover length=l;
length text $ 50;
input text $varying50. l;
file aprdata pad lrecl=80;
put text;
datalines;
Akron 04/05/99 04/09/99 175.00 298.45
Brown 04/12/99 05/01/99 125.00 326.78
Carnes 04/27/99 04/29/99 125.00 174.24
Denison 04/11/99 04/12/99 175.00 87.41
Fields 04/15/99 04/22/99 175.00 378.96
Jamison 04/16/99 04/23/99 125.00 346.28
;


Accepted Solutions
Solution
‎12-24-2015 01:13 PM
Super Contributor
Posts: 490

Re: Can someone explain this code to me?

[ Edited ]

First let us make sure that you know that:

DATALINES (or CARDS) Informs SAS that the input data resides inside the code (in-stream data) and immediately follows the DATALINES (or CARDS) statement.

 

Senond thing is:

You may use the INFILE statement with the DATALINES (or CARDS) to process instream data and still utilize other INFILE options.

 

And here in your example INFILE options missover and  length= are utilized in reading the in-stream data. Both you can read about here INFILE Statement

 

Finally, based on previous posts by you i can understand that you are preparing for the base certification. And what i hope is you do not be confused by this sample data code with the book. This code generate data used in the book and you are not asked to know every thing in that code at least for the base exam. You are not going to get any questions out of the exam scopes or reading difficult raw data not covered in the certification book.

View solution in original post


All Replies
Solution
‎12-24-2015 01:13 PM
Super Contributor
Posts: 490

Re: Can someone explain this code to me?

[ Edited ]

First let us make sure that you know that:

DATALINES (or CARDS) Informs SAS that the input data resides inside the code (in-stream data) and immediately follows the DATALINES (or CARDS) statement.

 

Senond thing is:

You may use the INFILE statement with the DATALINES (or CARDS) to process instream data and still utilize other INFILE options.

 

And here in your example INFILE options missover and  length= are utilized in reading the in-stream data. Both you can read about here INFILE Statement

 

Finally, based on previous posts by you i can understand that you are preparing for the base certification. And what i hope is you do not be confused by this sample data code with the book. This code generate data used in the book and you are not asked to know every thing in that code at least for the base exam. You are not going to get any questions out of the exam scopes or reading difficult raw data not covered in the certification book.

Occasional Contributor
Posts: 6

Re: Can someone explain this code to me?

Hi Mohammed, 

Can you tell me why they have 'text' there?

Super Contributor
Posts: 490

Re: Can someone explain this code to me?

"text" is just a variable name, you can replaced by any valid name...

Occasional Contributor
Posts: 6

Re: Can someone explain this code to me?

ok, but what does it do to the put statement? I know that put is the same as input but for writing data to an external file. Usually we have several variable for the number of column in the put statement but here we have "text" only.

Super Contributor
Posts: 490

Re: Can someone explain this code to me?

because as you can see. They red each line in the data lines as one string variable.

To get a better idea run the code without puting to file 

data new;
infile cards missover length=l;
length text $ 50;
input text $varying50. l;

datalines;
Akron 04/05/99 04/09/99 175.00 298.45
Brown 04/12/99 05/01/99 125.00 326.78
Carnes 04/27/99 04/29/99 125.00 174.24
Denison 04/11/99 04/12/99 175.00 87.41
Fields 04/15/99 04/22/99 175.00 378.96
Jamison 04/16/99 04/23/99 125.00 346.28
;
Occasional Contributor
Posts: 6

Re: Can someone explain this code to me?

I understand
Thanks Mohamed.
☑ This topic is SOLVED.

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

Discussion stats
  • 6 replies
  • 380 views
  • 2 likes
  • 2 in conversation