Hi
I am using proc means with proc format.
In the output data set in column x I can't see the groups that I defined in proc format.
Why?
How can I solve it?
proc format;
value ffmt
0-10='0-10'
10-50='10-50'
50-100='50-100'
100-high='100+'
;
run;
data tbl;
input ID x y;
cards;
1 0 100
2 5 110
3 30 120
4 40 130
5 50 140
6 60 150
7 70 160
8 80 170
9 90 180
10 110 190
;
run;
proc means data=tbl nway noprint;
class x;
var y;
format x ffmt.;
output out=output sum(y)=sum_y;
run;
Works for me:
proc format;
value ffmt
0-10='0-10'
10-50='10-50'
50<-100='50-100'
100<-high='100+'
;
run;
data tbl;
input ID x y;
cards;
1 0 100
2 5 110
3 30 120
4 40 130
5 50 140
6 60 150
7 70 160
8 80 170
9 90 180
10 110 190
;
run;
proc means data=tbl nway noprint;
class x;
var y;
format x ffmt.;
output out=output sum(y)=sum_y;
run;
proc print data=output noobs;
run;
Result:
x _TYPE_ _FREQ_ sum_y 0-10 1 2 210 10-50 1 3 390 50-100 1 4 660 100+ 1 1 190
First of all, remember to control your ranges. Eg, what group did you expect the value 10 to be in? Do like this
proc format;
value ffmt
0-10='0-10'
10<-50='10-50'
50<-100='50-100'
100<-high='100+'
;
run;
Also, what is wrong with your output data set? When I run this, I see exactly the groups you have defined?
If you look at the output data set (and not the output printed) you will see that in X column values are different
The FORMAT statement within PROC MEANS has a temporary effect. It groups the CLASS variable while PROC MEANS runs, but it does not permanently associate the CLASS variable with the format. You would need to repeat the FORMAT statement in a later step to see the formatted values instead of the actual values.
Works for me:
proc format;
value ffmt
0-10='0-10'
10-50='10-50'
50<-100='50-100'
100<-high='100+'
;
run;
data tbl;
input ID x y;
cards;
1 0 100
2 5 110
3 30 120
4 40 130
5 50 140
6 60 150
7 70 160
8 80 170
9 90 180
10 110 190
;
run;
proc means data=tbl nway noprint;
class x;
var y;
format x ffmt.;
output out=output sum(y)=sum_y;
run;
proc print data=output noobs;
run;
Result:
x _TYPE_ _FREQ_ sum_y 0-10 1 2 210 10-50 1 3 390 50-100 1 4 660 100+ 1 1 190
How did you examine the OUTPUT data set?
The output I get when using proc print on the output data set is:
Proc print data=output noobs;
run;
x | _TYPE_ | _FREQ_ | sum_y |
---|---|---|---|
0-10 | 1 | 2 | 210 |
10-50 | 1 | 3 | 390 |
50-100 | 1 | 4 | 660 |
100+ | 1 | 1 | 190 |
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.
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.