Hello. I wrote some proc tabulate code that is working for me with continuous outcome variables but not categorical outcome variables. I would appreciate any help you can provide. The data is a long file where all IDs have a pre record and some IDs have a post record. Here is the code. I cannot drop it in, sorry.
proc tabulate data=data format=6.1 nosep order=internal;
class group / descending;
class time;
var contvar;
table contvar*(n mean std nmiss),group*time;
run;
How would I get a table with n and % for categorical variables by group (sorted ascending) and time (pre and post) sorted descending?
Thanks!
Didn't the DESCENDING keyword on the CLASS statement work?
It seems to work for me.
data have;
do id=1 to 2;
do group=1 to 3;
do time=1 to 2;
row+1;
contvar=rand('integer',1000);
output;
end;
end;
end;
run;
proc tabulate data=have format=6.1 nosep ;
class group ;
class time / descending;
var contvar;
table contvar*(n mean std nmiss),group*time;
run;
@hein68 wrote:
Hello. I wrote some proc tabulate code that is working for me with continuous outcome variables but not categorical outcome variables. I would appreciate any help you can provide. The data is a long file where all IDs have a pre record and some IDs have a post record. Here is the code. I cannot drop it in, sorry.
proc tabulate data=data format=6.1 nosep order=internal;
class group / descending;
class time;
var contvar;
table contvar*(n mean std nmiss),group*time;
run;
How would I get a table with n and % for categorical variables by group (sorted ascending) and time (pre and post) sorted descending?
Thanks!
Since your Proc Tabulate code does not use any variable called ID why do you include " where all IDs have a pre record and some IDs have a post record. " That bit of trivia apparently has no obvious connection to this problem. If you are discussing the role of a variable then name the variable.
If you want Group to be ascending then why did you have the option /descending for the Group variable? The default for class variables is "ascending" but if you have a FORMAT applied to the variable(s) things may appear as if they are not ordered.
Strong hint: provide some example data in the form of a working data step and if your actual data has custom formats applied then the definitions of the formats, or at least enough to work with the example data.
Nearly 200 sessions are now available on demand in the Innovate Hub.
Watch Now →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.