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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 611 views
  • 0 likes
  • 3 in conversation