BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ronein
Meteorite | Level 14

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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 

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

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?

Ronein
Meteorite | Level 14

If you look at the output data set (and not the output printed) you will see that in X column values are different

 

Astounding
PROC Star

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.

Kurt_Bremser
Super User

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 
ballardw
Super User

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

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

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
  • 5 replies
  • 804 views
  • 1 like
  • 5 in conversation