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;
Just to understand. Is Classdata option working only in a case that there is one variable???
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;
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 )
Hi:
You should have received a WARNING with the 2 CLASSDATA options and then another error in your code, as shown below:
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:
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
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.