Hello,
Is there anyway that I can have a condition within a proc tabulate such that if for example when ord equals 1,3,4,5 (summarized continuous data - n mean std) then I have class, var and table statements and when ord equals 2,6,and 7 (summarized categorical data - counts and percents) I use different class, var and table statements. The reason why I need it in the middle is because the order of tables needs to remain.
Thanks in advance.
If I understand your problem correctly then no, you can't have conditional table statements within Proc Tabulate. What you can do is call Proc Tabulate multiple times and you can do this data driven.
Below some sample code to illustrate the approach.
%macro demo(type,name);
%if &type=1 %then
%do;
title "Table type 1 for &name";
proc tabulate data=sashelp.class;
where name = "&name";
class sex;
keylabel n=' ';
table sex;
run;
title;
%end;
%else
%if &type=2 %then
%do;
title "Table type 2 for &name";
proc tabulate data=sashelp.class;
where name = "&name";
class age;
keylabel n=' ';
table age;
run;
title;
%end;
%mend;
%demo(James);
proc format;
value $type
'Alfred'
,'Joyce'
,'Judy'
,'Louise'
,'Henry'
,'James'
,'Jane'
,'Janet'= '1'
'Jeffrey'
,'Alice'
,'Barbara'
,'Carol'
,'John'
,'Mary'
,'Philip'
,'Robert'
,'Ronald'
,'Thomas'
,'William'='2'
other = 'na'
;
run;
data _null_;
set sashelp.class;
by name;
if first.name then
do;
cmd=cats('%demo(',put(name,$type.),',',name,')');
call execute(cmd);
end;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.