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 |
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.