Help using Base SAS procedures

Formatting Class variable but not analytical variable

Reply
Frequent Contributor
Posts: 139

Formatting Class variable but not analytical variable

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;
Super Contributor
Super Contributor
Posts: 365

Re: Formatting Class variable but not analytical variable

Posted in reply to darrylovia
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
SAS Employee
Posts: 1

Re: Formatting Class variable but not analytical variable

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.
Ask a Question
Discussion stats
  • 2 replies
  • 99 views
  • 0 likes
  • 3 in conversation