BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Yanni_C
Fluorite | Level 6

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.

Yanni_C_0-1675252024798.png

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
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.

--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26
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.

--
Paige Miller
FreelanceReinh
Jade | Level 19

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;
PaigeMiller
Diamond | Level 26

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 )

--
Paige Miller
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1443 views
  • 1 like
  • 3 in conversation