BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8
how to delete first record , if the first record is blank?
8 REPLIES 8
CurtisMack
Fluorite | Level 6
In what context?
SASPhile
Quartz | Level 8
i will get data in excel and at times the data in the second row (first row being the header they become sas variable names in sas dataset) will be empty and starting from third row the data begins.so once we have the dataset the first record will be blank.
CurtisMack
Fluorite | Level 6
Something like this?
-------------------------------------

data stuff;
x = "A"; output;
x = " "; output;
x = "B"; output;
x = "C"; output;
run;

data stuff;
set stuff(where = (not missing(X)));
run;
SASPhile
Quartz | Level 8
Curtis,
this is same as following right?

data stuff;
set stuff;
if x=" " then delete;
run;

say if i have address field and some of the values can be missing for address field, but not the entire record. then we cannot use either your logic or mine.

but there is a chance that first record(all fields) can be blank, then how to delete?
CurtisMack
Fluorite | Level 6
They are almost the same except my version might be a litle faster because it wouldn't read the null record into the data step vector. This might work for you.
----------------------------------------------
data stuff;
x = "A"; y = 1; output;
x = " "; y = 1; output;
x = " "; y = .; output;
x = "B"; y = 1; output;
x = "C"; y = 1; output;
run;
data stuff;
set stuff;
if not missing(compress(cats(of _all_),'.'));
run;
SASPhile
Quartz | Level 8
this is cool. can y be of any data type?in your example it is numeric data type.
the reason for asking for datatype is in the if condition what does '.' do in the compress function?
CurtisMack
Fluorite | Level 6
I think this will work with any number of variables of any type.

I just had an example of one character and one numeric to show that it would work with both types. The CATS(_ALL_) will concatinate all of the variables in the data step vector into a single string. The numerics will be automatically converted to strings using a default format so the missing numerics will be a '.'. The missing characters will of course be blank. The compress( ,'.') removes those periods from the missing numerics, so if all of the values were missing all that will be left is spaces which MISSING is evalutate as true.
SASPhile
Quartz | Level 8
it makes sense.
thanks,

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1819 views
  • 0 likes
  • 2 in conversation