DATA Step, Macro, Functions and more

Delete empty columns

Reply
Contributor
Posts: 40

Delete empty columns

What's the easiest way to remove empty columns/variables from a data set? As in when I get a subset of data from my main dataset, if there are columns which are empty/null in that subset, how do I write a program to remove such variables from the subset?

 

Thanks!

Super User
Posts: 10,044

Re: Delete empty columns

data class;
 set sashelp.class;
 call missing(name,age);
run;



ods select none;
ods output nlevels=temp;
proc freq data=class nlevels;
tables _all_;
run;
ods select all;
proc sql noprint;
 select tablevar into : drop separated by ' '
  from temp 
   where NNonMissLevels=0;
quit;
data want;
 set class(drop=&drop);
run;
Contributor
Posts: 40

Re: Delete empty columns

Is there a way to do this without specifying the names of the variables? 

Super User
Posts: 10,044

Re: Delete empty columns


???  That was exactly what I am doing . No need any variable name, just run the code and gave you what you want .

Super User
Posts: 5,437

Re: Delete empty columns

Instead of worry about empty columns, why not just keep the ones that you actually need?
Data never sleeps
Contributor
Posts: 40

Re: Delete empty columns

It's like this, these variables have values for certain years. But  are empty for some years. So when I want to extract a dataset for a particular year from the main dataset, I want in that dataset all the null columns not to appear. Could you advice me how to do this?

 

 

Super User
Posts: 5,437

Re: Delete empty columns

1. Take control over your data. This could involve having a meta data table containing information of which variables appear what years. Then you could dynamically build a keep statement during you filtering. Or
2. Search these forums for a more generic solution. There have been multiple similar inquiries the last couple of months.
Data never sleeps
Ask a Question
Discussion stats
  • 6 replies
  • 2432 views
  • 7 likes
  • 3 in conversation