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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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