BookmarkSubscribeRSS Feed
eagles_dare13
Obsidian | Level 7

I am creating a data step as follows:

data TEST;

   INFILE DATALINES DSD;

   INPUT  CODE: $4. FLAG_IND: $1.;

   DATALINES;

0111,Y

0115,N

;

if last then do;

hlo ='O';

FLAG_IND ='U';

output;

end;

run;

My desired output is:

CODE    FLAG_IND   HLO

0111        Y

0115        N

               U                O

But I get:

Statement is not valid or it is used out of proper order.

Is my syntax not right? I was following this:

http://www.pharmasug.org/proceedings/2011/CC/PharmaSUG-2011-CC19.pdf

Page 2

1 REPLY 1
ballardw
Super User

The log should be pointing to this line for the error:

if last then do;

Firstly, code precedes the datalines statement.

Second the example uses the END= option for reading a dataset which is not available for DATALINES.

Example:

set Med_tmp end = last;

To use the End option first read the dataset and then use the code from the example on the SET statement reading the set just created.

Or read the data from an external file and use the End=last  option on the INFILE statement.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 1167 views
  • 0 likes
  • 2 in conversation