I have a data set which has many missing values. I am trying to eliminate the missing values by using if then else statement. But I could not do that. The dataset which I have is in labelled and formatted form.
data sample;
input age $gender $race;
datalines;
4 M
1 F hispanic
3 F black
. M
7 Hispanic
5 M white
;
output
I want to include only the observations with full data eliminating the missing values. For example, from the above data I need to include only 2nd and 6th rows in the data set eliminating all the rows with missing observations. How can I do that.
Try
if cmiss(of _numeric_, of _character_) = 0;
@PGStats wrote:Try
if cmiss(of _numeric_, of _character_) = 0;
Can we just :
if cmiss(of _all_) = 0;
Is your data already in a SAS data set, or are you needing to read it in? This variation would overcome problems with INPUT when there are fewer than 3 items on a line:
data want;
input @;
if scan(_infile_, 3, ' ')=' ' then delete;
else input age gender $ race $;
datalines;
4 M
1 F hispanic
3 F black
. M
7 Hispanic
5 M white
;
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.
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.