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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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