BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mirmousavi
Calcite | Level 5

Hi everyone,

 

I try to count number of missing for each variable of my dataset with following codes.

proc format;

value $missfmt '-9'='Missing' '-8'='Missing' '-6'='Missing' '-7'='Missing' ''='Missing' ' '='Missing' other='Not Missing';

value missfmt   . ='Missing'   -9='Missing'   -8='Missing'   -6='Missing' -7='Missing'   other='Not Missing';

run;

 

data pii;

set pii.pii_trad_nochc;

format _NUMERIC_ missfmt. _CHAR_ $missfmt.;

run;

 

proc freq data=pii;

format _NUMERIC_ missfmt. _CHAR_ $missfmt.; /* apply format for the duration of this PROC */

table _all_ / nocum;

run;

I have 600 variables and the proc freq gives me the number of missing for all of them.  The question is how to save the output in one dataset?

Please advise,

Bibi

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
*Run frequency for tables;
ods table onewayfreqs=temp;
proc freq data=sashelp.class;
	table sex age;
run;

*Format output;
data want;
length variable $32. variable_value $50.;
set temp;
Variable=scan(table, 2);

Variable_Value=strip(trim(vvaluex(variable)));

keep variable variable_value frequency percent cum:;
label variable='Variable' 
	variable_value='Variable Value';
run;

*Display;
proc print data=want(obs=20) label;
run;

This is a more complicated version here, that gives a nicer/clean report if needed. 

 

https://gist.github.com/statgeek/2de1faf1644dc8160fe721056202f111

View solution in original post

5 REPLIES 5
Shmuel
Garnet | Level 18

Add OUTPUT close to proc freq. See documentation.

Rick_SAS
SAS Super FREQ

Can you say more about what you need for output?

 

Is your goal to compute the count of missing values for each variable? If so, see the article "Count the number of missing values for each variable."

 

If you want one-tables for all variables (missing and nonmissing), you can use

ODS OUTPUT OneWayFreqs=FreqOut;

to get the output data set, like this:

 


proc format;
 value $missfmt ' '='Missing' other='Not Missing';
 value  missfmt  . ='Missing' other='Not Missing';
run;
 
proc freq data=sashelp.heart; 
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;
ods output OneWayFreqs=FreqOut;
run;

proc print; run;
ballardw
Super User

BTW, you may find it simpler to use comma separated lists of values  to make such formats:

 

proc format;
value $missfmt 
'-9', '-8', '-6', '-7', '', ' '='Missing' 
other='Not Missing';

value missfmt 
. , -9, -8, -6, -7 ='Missing' 
other='Not Missing'
;

run;
Reeza
Super User
*Run frequency for tables;
ods table onewayfreqs=temp;
proc freq data=sashelp.class;
	table sex age;
run;

*Format output;
data want;
length variable $32. variable_value $50.;
set temp;
Variable=scan(table, 2);

Variable_Value=strip(trim(vvaluex(variable)));

keep variable variable_value frequency percent cum:;
label variable='Variable' 
	variable_value='Variable Value';
run;

*Display;
proc print data=want(obs=20) label;
run;

This is a more complicated version here, that gives a nicer/clean report if needed. 

 

https://gist.github.com/statgeek/2de1faf1644dc8160fe721056202f111

mirmousavi
Calcite | Level 5

Thank you Reeza,

 

The GitHub link was perfect.  It worked out great for my purpose.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 7775 views
  • 6 likes
  • 5 in conversation