DATA Step, Macro, Functions and more

last line in the data set is blank after reading in SAS

Reply
Super Contributor
Posts: 318

last line in the data set is blank after reading in SAS

either by proc import or data step with infile to read in .csv files, I notice that the last line in the data sets is blank.

Actually the last line in the .csv file has no values at all. Somehow when SAS read the data, it stops at the line below the last line in CSV.

 

How to solve this issue? Thanks.

Super User
Posts: 5,432

Re: last line in the data set is blank after reading in SAS

Posted in reply to fengyuwuzu
Are you sure that there are no LF/CR at your last lkne with values?
Data never sleeps
Respected Advisor
Posts: 4,927

Re: last line in the data set is blank after reading in SAS

Posted in reply to fengyuwuzu

With data step import, you could add the statement

 

if not missing(cats(of _all_));

to remove any line (observation) that is totally empty (missing).

PG
Super Contributor
Posts: 436

Re: last line in the data set is blank after reading in SAS

Could you please what 'cats(of _all_)' will do in following if clause?

 

if not missing(cats(of _all_));

 

Super User
Posts: 7,831

Re: last line in the data set is blank after reading in SAS

[ Edited ]
if not missing(cats(of _all_));

That only works if all variables are character, as numeric variables will render a dot in the cats(of _all), causing the string to be non-missing.

In order for this to work,

options missing = ' ';

needs to be set.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 7,831

Re: last line in the data set is blank after reading in SAS

[ Edited ]
Posted in reply to fengyuwuzu

fengyuwuzu wrote:

either by proc import or data step with infile to read in .csv files, I notice that the last line in the data sets is blank.

Actually the last line in the .csv file has no values at all.


 

That is as expected. An empty line in a .csv file will cause the input statement to read nothing, so the variables stay "missing" for this iteration of the data step.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 5 replies
  • 280 views
  • 1 like
  • 5 in conversation