Hi,
I am trying to use classdata to limit which combinations of variables should be processed by proc means. Unfortunately, it appears that it has no effect - I am getting all the combinations including totals despite using classdata exclusive:
proc means data=foo classdata=classdata1 exclusive;
class var1 var2 var3 var4 var5 var6;
format var6 $varsix.;
output out=procmeans(drop=_TYPE_ _FREQ_) n=count;
run;
What am I doing wrong?
Turns out I can achieve what I need by just not dropping the counts from procmeans2 and using classdata1 as my final dataset. Still, is classdata doing what it is supposed to in my original code?
Please post the complete log from that step, and inspect your CLASSDATA1 dataset.
Also consider the impact of using format $VARSIX.
I have managed to reproduce this with sashelp.cars:
proc format;
value hp
low-<150 = "low"
150-high = "high";
proc means data=sashelp.cars noprint;
class Origin Make Type DriveTrain;
types Origin*Make*Type*DriveTrain Origin*Make*DriveTrain Origin*DriveTrain;
output out=procmeans1(keep=Origin Make Type DriveTrain) n=count;
run;
proc sort data=procmeans1;
by Origin Make Type DriveTrain;
run;
proc means data=sashelp.cars noprint completetypes;
class Origin Make Type DriveTrain Horsepower;
format Horsepower hp.;
output out=procmeans2(keep=Origin Make Type DriveTrain Horsepower) n=count;
run;
proc sort data=procmeans2;
by Origin Make Type DriveTrain Horsepower;
run;
data classdata1;
merge procmeans1(in=cd) procmeans2(where=(not missing(Horsepower)));
by Origin Make Type DriveTrain;
if cd;
run;
proc means data=sashelp.cars noprint classdata=classdata1 exclusive;
class Origin Make Type DriveTrain Horsepower;
format Horsepower hp.;
var Horsepower;
output out=procmeans n=count;
run;
What I need is a dataset like classdata1 with counts for each horsepower pool calculated, even if the count is 0 (I need to feed this dataset to proc freq later). In other words, the classdata1 dataset with count column in it.
Turns out I can achieve what I need by just not dropping the counts from procmeans2 and using classdata1 as my final dataset. Still, is classdata doing what it is supposed to in my original code?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.