Hi, I am doing summary for each columns and want to know missing and non-missing percentage in the data. I have to classify it on country level.
Ideally, I have to calculate percentage of missing and non-missing sale (another variable in my data) on country level. Can anyone help please.
data test;
set sashelp.prdsal2;
sale=0;
if actual> predict then sale=.; run;
proc summary data=test;
class country;
var sale;
run;
Thanks.
You might need PROC TABULATE
PROC TABULATE DATA=WORK.TEST;
CLASS COUNTRY / ORDER=UNFORMATTED MISSING;
CLASS sale / ORDER=UNFORMATTED MISSING ;
TABLE COUNTRY,sale*RowPctN ;
RUN;
Do you mean you are after this?
data test;
set sashelp.prdsal2;
sale=0;
if actual> predict then sale=.; run;
proc freq data=test noprint;
tables country*sale/missing out=want;
run;
No, as per my problem I want to calculate percentage within each country assuming each country has 100% population and within country missing and non-missing percentage.
You might need PROC TABULATE
PROC TABULATE DATA=WORK.TEST;
CLASS COUNTRY / ORDER=UNFORMATTED MISSING;
CLASS sale / ORDER=UNFORMATTED MISSING ;
TABLE COUNTRY,sale*RowPctN ;
RUN;
PROC TABULATE DATA=WORK.TEST out=best (drop=_type_ _page_ _table_);
CLASS COUNTRY / ORDER=UNFORMATTED MISSING;
CLASS sale / ORDER=UNFORMATTED MISSING ;
class resale/ ORDER=UNFORMATTED MISSING ;
TABLE COUNTRY,sale*RowPctN ;
table COUNTRY,resale* RowPctN;
RUN;
PROC TABULATE DATA=WORK.TEST;
CLASS COUNTRY / ORDER=UNFORMATTED MISSING;
CLASS resale / ORDER=UNFORMATTED MISSING;
CLASS sale / ORDER=UNFORMATTED MISSING ;
TABLE /* Row */ COUNTRY,
/* Col */ sale*RowPctN resale*RowPctN ;
RUN;
Check how row's and Columns are controlled
@SuryaKiran wrote:
PROC TABULATE DATA=WORK.TEST; CLASS COUNTRY / ORDER=UNFORMATTED MISSING; CLASS resale / ORDER=UNFORMATTED MISSING; CLASS sale / ORDER=UNFORMATTED MISSING ; TABLE /* Row */ COUNTRY, /* Col */ sale*RowPctN resale*RowPctN ; RUN;
Check how row's and Columns are controlled
Or for variables that you are doing the same things for group with () and you can have multiple variables on a single CLASS statement as long as all options are the same
PROC TABULATE DATA=WORK.TEST; CLASS COUNTRY / ORDER=UNFORMATTED MISSING; CLASS resale sale / ORDER=UNFORMATTED MISSING; TABLE COUNTRY, (sale resale)*RowPctN ; RUN;
Proc tabulate will also honor variable lists such as QR:, var1-var9 or ThisVar--ThatVar to use all variables in the list in Class and Var statements as well as in the Table definition.
You can also use the special variable lists _numeric_ or _character_ .
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.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.