DATA Step, Macro, Functions and more

Data read problem

Frequent Contributor
Frequent Contributor
Posts: 82

Data read problem

I tried to create the data set below, however, I could only read 3 records intead of all of the 7 records.  I am wondering what is wrong.  Thank you very much !


data med_search;
input med $ 100 ;
omeprazole (Prilosec, Prilosec OTC)
dexlansoprazole (Dexilent, Kapidex)
rabeprazole (Aciphex)
pantoprazole (Protonix)
Esomeprazole (Nexium)
Lansoprazole (Prevacid)
Zegerid (omeprazole with sodium bicarbonate)

Trusted Advisor
Posts: 1,256

Re: Data read problem

Hi @Ivy,


There are two issues:

  1. The missing period after the informat specification ($ 100) means that column input is requested, reading from column 100 alone (i.e. only one character!). Since none of the data lines is that long, "SAS went to a new line when INPUT statement reached past the end of a line." (Did you notice this NOTE in the log?)
  2. With the missing period added, it would be formatted input, but the informat length 100 exceeds the record length, so that SAS would again "flow over" to the next observation.


One possible solution is to use list input with the "&" modifier, without which SAS would stop reading a line at the first blank (i.e. read only the first "word"):

input med &$100.;

SAS would now read until the first double blank or the end of the data line, whichever comes first. Hence, you might lose portions of the drug names if double blanks occurred. Therefore, a more robust approach would be to use formatted input in conjunction with the TRUNCOVER option of the INFILE statement (which needs to be inserted in order to specify this option). Without TRUNCOVER, the default option would be FLOWOVER with the unwanted effect described in item 2 above.

infile datalines truncover;
input med $100.;
Frequent Contributor
Frequent Contributor
Posts: 82

Re: Data read problem

Posted in reply to FreelanceReinhard
Thank you very much, FreelanceReinhard ! That works !
Ask a Question
Discussion stats
  • 2 replies
  • 1 like
  • 2 in conversation