BookmarkSubscribeRSS Feed
milts
Pyrite | Level 9
hello

i have a data set containing columns x y z. data set contains 10 records. i want to check if x has a value for each observation. however if all 10 records have a value of missing or 0 in x, i want to delete the column x. how can i do that?

thanks!
4 REPLIES 4
deleted_user
Not applicable
Hi,

For this we need to run PROC MEANS with (N NMISS MIN MAX) on the data first to identify those variables having missing values or zero's.
After this we can drop those variables whose N=NMISS or (MIN=0 and MAX=0) by using DROP or KEEP.

Hope this will help you
advoss
Quartz | Level 8
if you are generating this table in a data step, you could create a retained variable to count the number of time that x is missing and then on the last observation, compare that variable with _n_ and if they are equal conditionally execute a data step to drop that variable...like:
data xyz;
set abc(keep=x y z) end=lastone;
retain x_missing 0;
x_missing = x_missing + missing(x);
if lastone then do;
if x_missing = _n_ then call execute('data def;set xyz(keep=y z);run;');
end;
run;
milts
Pyrite | Level 9
i see. thanks a lot for the help !
deleted_user
Not applicable
Try this


data d1;
set s1;
if x=y=z then flag='v';
run;

data d2;
set d1;
if flag ne 'v' then delete;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4 replies
  • 2007 views
  • 0 likes
  • 3 in conversation