BookmarkSubscribeRSS Feed
Yoko
Obsidian | Level 7

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. 

 

data mydata;
input id score1 score2;
datalines;
alfred 9 10
alice 13 12
barbara 10 8
carol . 5
joe . 9
;
 
proc tabulate data=mydata;
var score1 score2;
table score1 score2, n nmiss min max;
run;

 

Please let me know if you know how to suppress the entire row (n, nmiss, min, max). 

 

Thank you, 

Yoko

 

3 REPLIES 3
ballardw
Super User

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.

 

 

mkeintz
PROC Star

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.  

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
LinusH
Tourmaline | Level 20

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

τ-ARGUS (cbs.nl)

 

Data never sleeps

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
  • 3 replies
  • 226 views
  • 0 likes
  • 4 in conversation