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

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 943 views
  • 1 like
  • 3 in conversation