I am checking the variables with missing observations in my dataset (using the code below). Now, I want to remove the variables that contain no observations from my dataset. I think about 10% of my variables are all missing observations. My sample size is 2100 and I have 1500 variables. I appreciate your suggestions. Thanks
data count_missing; set &dataset; run;
proc format;
value $missfmt ' '='Missing' other='Not Missing';
value missfmt . ='Missing' other='Not Missing';
run;
proc freq data=count_missing;
format _CHAR_ $missfmt.; /* apply format for the duration of this PROC */
tables _CHAR_ / missing missprint nocum nopercent;
format _NUMERIC_ missfmt.;
tables _NUMERIC_ / missing missprint nocum nopercent;
run;
Example using SASHELP.ZIPMIL (which has lots of missings), using the NLEVELS option of PROC FREQ
ods output nlevels=nlevels;
proc freq data=sashelp.zipmil nlevels;
format _CHAR_ $missfmt.; /* apply format for the duration of this PROC */
tables _CHAR_ / missing missprint nocum nopercent;
format _NUMERIC_ missfmt.;
tables _NUMERIC_ / missing missprint nocum nopercent;
run;
proc sql noprint;
select tablevar into :varnames separated by ' ' from nlevels where nnonmisslevels=0;
quit;
data want;
set sashelp.zipmil(drop=&varnames);
run;
Example using SASHELP.ZIPMIL (which has lots of missings), using the NLEVELS option of PROC FREQ
ods output nlevels=nlevels;
proc freq data=sashelp.zipmil nlevels;
format _CHAR_ $missfmt.; /* apply format for the duration of this PROC */
tables _CHAR_ / missing missprint nocum nopercent;
format _NUMERIC_ missfmt.;
tables _NUMERIC_ / missing missprint nocum nopercent;
run;
proc sql noprint;
select tablevar into :varnames separated by ' ' from nlevels where nnonmisslevels=0;
quit;
data want;
set sashelp.zipmil(drop=&varnames);
run;
Also, your formats are not needed, even though I left them in the code.
Hello,
I advise you to search the SAS-communities first to find your answer (before asking your question).
It may save you some valuable time!
This question, for example, is posted rather frequently.
See for example:
Deleting Variables with Only Missing Values from Dataset with 4000+ Variables
You will find multiple solutions there.
Koen
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.