BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

Hello

I am using sashelp.class raw data in order to create a summary report.

I want to add categories in age varaible that are not in the raw data (will get values 0)

I also want o to add category of Sex variable that is not in the raw table (will get values 0)  

I want to use classdata option in proc tabulate in order to show categories with value 0.

The problem is that it is not working.

Any idea why?

Data level1;
input sex $1.;
cards;
F
M
T
;
Run;

proc format;
value $sex
"F"="Female"
"M"="Male"
"T"="Trans"
;
Run;

Data level2;
input age;
cards;
10
11
12
13
14
15
16
17
18
;
Run;

proc tabulate data=ashelp.class   classdata=level1   classdata=level2;
class sex age;
var height;
table sex=''  all='ALL',
 (age*N*f=8.  all='ALL'    age *height=''*mean*f=8.1  all='ALL');
Run;

 

 

5 REPLIES 5
Ronein
Meteorite | Level 14

Just to understand. Is Classdata option working only in a case that there is one variable???

Tom
Super User Tom
Super User

CLASSDATA option needs to be specified once and should be a dataset that has the set of combinations you want to force to appear.  So something like:

proc sql ;
create table classdata as
select *
from level1,level2
;
quit;
Ronein
Meteorite | Level 14

May you please show the full solution with classdata option ? (I understand that you created a table that has all required combinations of var sex and var age but it is still not working )

 

 

Cynthia_sas
SAS Super FREQ

Hi:

  You should have received a WARNING with the 2 CLASSDATA options and then another error in your code, as shown below:

tab_error.png

  However, you can generate the data for the CLASSDATA file a different way, as shown in the program below, which produces this result:

Result showing TAB code fixed using new CLASSDATA:

tab_good_results.png

 

Code to make classdata:

Data myclass;
length sex $1 age 8;
do sex = 'F', 'M', 'T';
  do age = 10 to 18 by 1;
     output;
  end;
end;
Run;

proc format;
value $sex
"F"="Female"
"M"="Male"
"T"="Trans"
;
Run;
 

 

Hope this helps,

Cynthia

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
  • 5 replies
  • 808 views
  • 0 likes
  • 3 in conversation