BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

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;

2 REPLIES 2
Patrick
Opal | Level 21

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.

Kurt_Bremser
Super User

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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 618 views
  • 0 likes
  • 3 in conversation