Hello
I am using proc tabulate and I want to see also categories with zero count(or zero sum..)
In data set SAShelp.class there are 2 categories for varaible Sex : M and F.
I want to show also another category called :Trans
I am using classdata option but I get an error. ("class varaible sex was not found in the preload data set)
I found that If I give another name "T" instead of "Trans" then it works well.
MAy anyone solve the issue please and explain why if length longer than 1 then I get error?
Data levels;
input sex $5.;
cards;
F
M
Trans
;
Run;
proc tabulate data=sashelp.class classdata=levels;
class sex;
table sex,n pctn;
Run;
From the docu here:
Restriction | The CLASSDATA= data set must contain all class variables. Their data type and format must match the corresponding class variables in the input data set. |
Sex from sashelp.class has a length of $1 so a string of Trans is not possible. Given that you want Proc Tabulate to print possible values it also wouldn't make sense to allow a longer string for the classdata table.
You could populate T into your classdata table and then create a format used in Proc Tabulate which prints T as Trans.
The variables must be defined identically in the source and classdata datasets. SEX in sashelp.class has a length of 1, so you must define it with that length in the classdata dataset.
Therefore, this works:
proc format;
value $sex
"F"="Female"
"M"="Male"
"T"="Trans"
;
run;
Data levels;
input sex $1.;
cards;
F
M
T
;
proc tabulate data=sashelp.class classdata=levels;
format sex $sex.;
class sex;
table sex,n pctn;
run;
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 25. Read more here about why you should contribute and what is in it for you!
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.