BookmarkSubscribeRSS Feed
darrylovia
Quartz | Level 8
Hello SAS Forum Users,

I'm trying to create a report that bins my variable into groups (say quartiles) and then find the mean for the variable in the bin. When I use a format in proc summary, the format applies to both the binned value(class variable) and the analytical variable.

See the below code as an example with the problem that I am having. Using the SASHELP tables, the output data set has the class variable, mean and std all formated with the quartilefmt. Is there a way to only apply the format to the class variable, so I can see the mean and std with no formatting?

Thanks



proc format;
value quartilefmt
low - 43155 = '1'
43155 <- 118849 = '2'
118849 <- 336513 = '3'
336513 <- high = '4';

proc summary data=sashelp.shoes nway;
class inventory;
format inventory quartilefmt.;
var inventory;
output out=inventory_by_quartiles mean=mean std=std;
run;
2 REPLIES 2
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello Darrylovia,

I had the same problem and to solve it created a copy of inventory variable, applied format to it and used as a class variable:
[pre]
data i;
set sashelp.shoes;
inv=inventory;
run;
proc summary data=i nway;
class inv;
format inv quartilefmt.;
var inventory;
output out=inventory_by_quartiles mean=mean std=std;
run;
[/pre]
I should also notice that without NWAY option you will get total mean and std that could be useful.
Sincerely,
SPR
RSRay_SAS
SAS Employee
Using a DATA Step view (data i / view = i) will avoid making a copy of the original data set which could be important if it is large. The new column will exist only in memory for single pass processing.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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