BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
asgee
Obsidian | Level 7

Hi all,

 

I have a dataset with around 98 variables. The variables are a mix of both character and numeric variables. The variables in the dataset are in a fixed order. 

 

I would like to select only variables #42 through #91, but keep the observations (or rows) that do not have missing data. Since variables #42 through #91 are both Character and Numeric variables, missing data has been identified as either "." or " ". 

 

Essentially, I still need every single variable (Variables # 1 through #98), but want to drop any observations based on missingness conditioning on variables 42-91. 

 

I've tried to do the code below but ended up with 0 observations (based on visual inspection alone I should have some rows left): 

*Using Variable Names;
data want;
set have;
if ("nameofvariable42" -- "nameofvariable91") = . or " " then delete;
run;


*Using Variable Numbers;
data want;
set have;
if (varnum between 42 and 91) = . or " " then delete;
run;

 

I've tried it in both methods (using the variable names & using the variable numbers) and ended up with the same result.

 

An error in the log stated that character values were converted to numeric. Not sure if this has something to do with combining both Character and Numeric variables at the same time...  

 

In any case, any help would be much appreciated! 

 

Thanks,

AG

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

To specify a list of variables based on position use double hyphen.

firstvar -- lastvar

To count the number of missing values in a list of mixed numeric and character variables use the CMISS() function.

So combining these it looks like you want to do:

data want;
  set have (keep = firstvar -- lastvar);
  if cmiss(of firstvar -- lastvar) then delete;
run;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

To specify a list of variables based on position use double hyphen.

firstvar -- lastvar

To count the number of missing values in a list of mixed numeric and character variables use the CMISS() function.

So combining these it looks like you want to do:

data want;
  set have (keep = firstvar -- lastvar);
  if cmiss(of firstvar -- lastvar) then delete;
run;
asgee
Obsidian | Level 7

@Tom  Thanks so much! Works perfectly 🙂 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 4886 views
  • 2 likes
  • 2 in conversation