BookmarkSubscribeRSS Feed
tradepeter
Calcite | Level 5

Hello all:

I wonder if you can calculate percentage of nonmissing values using proc tabulate. What I need is sth. like

        Mean

var   Std

        N

        Percent of nonmissing values

Although the statistic can be calculated as simple as N/(N + NMISS), I cannot seem to find a way to do that directly.

Thanks,

Peter

1 REPLY 1
Cynthia_sas
SAS Super FREQ

Hi:

  I'm confused. N+NMISS would equal the total number ...since, by definition, the N statistic is the count of non-MISSING values and NMISS is the count of MISSING values. But, for example if you have 4 observations:

name age gender height

alan    10    M          68.0

bob     11                .

carl      .      M          72.0

dave   12                 72.4

you have 4 total observations. NAME has N=4 and NMISS=0; AGE has N=3 and NMISS=1; HEIGHT has N=3 and NMISS=1 and GENDER has N=2 and NMISS=2....so when you show Percent of non-missing, I get confused because the PCTN is automatically calculated with N (so it would be the percent of the nonmissing). But TABULATE will not "add" N+NMISS automatically. On the other hand, look at the difference the MISSING option has in PROC FREQ in the calculate of percentages.

cynthia

data testdata;

  infile datalines dlm=',' dsd;

  input name $ age gender $ height;

datalines;

alan,  10,   M,    68.0

bob,   11,    ,      .

carl,   .,   M,    72.0

dave,  12 ,   ,    72.4

;

run;

   

ods listing;

proc print data=testdata;

run;

proc freq data=testdata;

title 'freq with missing option';

  tables name gender age height / missing;

run;

proc freq data=testdata;

title 'freq without missing option';

  tables name gender age height ;

run;

proc tabulate data=testdata missing;

title 'tabulate with n and nmiss';

  var age height;

  table age,(mean std n nmiss pctn);

  table height,(mean std n nmiss pctn);

run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1 reply
  • 1604 views
  • 0 likes
  • 2 in conversation