BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
js5
Pyrite | Level 9 js5
Pyrite | Level 9

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?

1 ACCEPTED SOLUTION

Accepted Solutions
js5
Pyrite | Level 9 js5
Pyrite | Level 9

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?

View solution in original post

3 REPLIES 3
js5
Pyrite | Level 9 js5
Pyrite | Level 9

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.

js5
Pyrite | Level 9 js5
Pyrite | Level 9

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: 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
  • 3 replies
  • 632 views
  • 0 likes
  • 2 in conversation