I want to filter and delete the columns with empty values.
In the picture below, I want to keep COL129 and COL130 after filtering, and delete other columns.
I am new to sas and would appreciate it if you could tell me how to program.
proc summary data=have;
var col129-col137;
output out=ns(drop=_type_ _freq_) nmiss=;
run;
proc transpose data=ns out=ns_t;
run;
proc sql noprint;
select _name_ into :names from ns_t where col1>0;
quit;
data want;
set have(drop=&names);
run;
This code is un-tested. If you want tested code, we need code provided as working SAS data step code. We cannot work from screen captures, and I personally never download attachments. Please, from now on, provide data as working SAS data step code which you can type in yourself, or use this macro to create. Do not provide data in file attachments or as screen captures.
proc summary data=have;
var col129-col137;
output out=ns(drop=_type_ _freq_) nmiss=;
run;
proc transpose data=ns out=ns_t;
run;
proc sql noprint;
select _name_ into :names from ns_t where col1>0;
quit;
data want;
set have(drop=&names);
run;
This code is un-tested. If you want tested code, we need code provided as working SAS data step code. We cannot work from screen captures, and I personally never download attachments. Please, from now on, provide data as working SAS data step code which you can type in yourself, or use this macro to create. Do not provide data in file attachments or as screen captures.
Later readers adopting this solution may want to add separated by ' ' to the INTO clause.
select _name_ into :names separated by ' ' from ns_t where col1>0;
Thanks, @FreelanceReinh
and I'm sure I would have caught that if I actually had data in a workable form to work with (hint hint @Yanni_C )
Adding:
It looks like the data shown is the output from PROC TRANSPOSE. If that is the case, then that seems like an unnecessary step to determine which variables are "complete" and which are "incomplete" and have missing values. And also, you then have to work with data that has the un-intuitive and essentially meaningless variable names like COL137.
But I can't write code for the un-transposed data.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.