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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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