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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 1086 views
  • 0 likes
  • 2 in conversation