Hello,
I want to show a summary (n, nmiss, min, and max) of variables in my data.
But, I want to suppress a row(s) if n <=5.
Here is a sample data and proc tabulate to get n, nmiss, min, and max.
I want to suppress data of score 1 because its n =3.
Please let me know if you know how to suppress the entire row (n, nmiss, min, max).
Thank you,
Yoko
Presummarize your data and use that set for the output. Then you can filter on values in the data set.
Proc Tabulate won't know "n", or any other statistic, until the output is created.
Consider that proc tabulate can have multiple "n" statistics in any given row (multiple variables in the column dimension). Any "n<=5" would require some convoluted way to deal with each possible different column.
Note: you may want to be a bit more careful in your example data. You only provided 5 example rows and want to suppress "n<=5". So all of your data is suppressed. Nothing to show.
And what exactly would "suppress" mean? Not show the row header? Show the row header but Missing for all values?
This may give you an example for summarizing the data. However more complex data /summaries likely require more examples of what is needed.
data mydata; input id $ score1 score2; datalines; alfred 9 10 alice 13 12 barbara 10 8 carol . 5 joe . 9 ; proc means data=mydata STACKODSOUTPUT n nmiss min max; var score1 score2; ods output summary=stacked; run;
Depending on exactly what you expect to display in the final output the data set Stacked may need additional manipulation in a data set.
This program runs proc tabulate only of variables with minimum values greater than 5. If there are no such variables, no proc tabulate will be invoked.
data mydata;
input score1 score2 ;
datalines;
10 110
11 111
2 112
13 113
14 114
15 115
run;
data _null_;
set mydata end=end_of_data;
array s {*} score1 score2 ;
array names {2} $32 _temporary_ ("SCORE1","SCORE2");
do v=1 to dim(s);
if names{v}^=' ' then do;
if 0<=s{v}<=5 then names{v}=' ';
end;
end;
if countw(catx(' ',of names{*}))=0 then do;
put '*** Every VAR has at least one value < 5. ***';
put '*** No PROC TABULATE will be done. ***';
stop;
end;
if end_of_data;
call execute('proc tabulate data=mydata;');
call execute(catx(' ','var',of names{*},';'));
call execute(catx(' ','table',of names{*},', n nmiss min max',';'));
call execute('run;');
run;
When a variable has a value <=5 its name is removed from the NAMES array. That array of names is what gets submitted to the proc tabulate.
The "call execute" statement queues up SAS code to be run immediately after the current DATA step.
If this is a recurring requirement, you might want to look into T-argus (developed by (for?) Eurostat) and SAS macro package to communicate with T-argus (SAS2argus).
https://github.com/sdcTools/SAS2Argus
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
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.