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_ .
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: