Dear All:
I want to put the data into multiple bins (Groups). Just a small sample of my data is as follows
VAR_A VAR_B VAR_C
5 120 600
4 125 -45
25 200 85
I want to construct 5 groups for VAR_A and VAR_B and then put VAR_C in the appropriate groups
So, for example, VAR_A can have bins as follows
0-5
6-20
21-30
31-50
GE 51
Groups for VAR_B
1-5
6-10
11-50
51-100
GE 101
First, I want to find the frequency distribution for VAR_C for dual groups of VAR_ and VAR_B.
Finally, can I find the Average of VAR_C for these bins (Groups).
Thanx so much.
Randy
Use formats to define the group:
proc format lib=work;
value fmtvarA
0 - 5 = 1
6 - 20 = 2
21 - 30 = 3
31 - 50 = 4
51 - high = 5
;
valu fmtvarB
0 - 5 = 1
6 - 10 = 2
11 - 50 = 3
51 - 100 = 4
101 - high = 5
;
run;
data temp1;
set have;
group_a = put(var_A, fmtvarA. );
group_b = put(var_B, fmtvarB. );
run;
Try to write your own code for next steps and post the code or the full log in case of issues.
Use formats to define the group:
proc format lib=work;
value fmtvarA
0 - 5 = 1
6 - 20 = 2
21 - 30 = 3
31 - 50 = 4
51 - high = 5
;
valu fmtvarB
0 - 5 = 1
6 - 10 = 2
11 - 50 = 3
51 - 100 = 4
101 - high = 5
;
run;
data temp1;
set have;
group_a = put(var_A, fmtvarA. );
group_b = put(var_B, fmtvarB. );
run;
Try to write your own code for next steps and post the code or the full log in case of issues.
With the format approach shown by @Shmuel you don't even need to change your data all most likely. Just apply the format to the variables in proc freq
Proc freq data=have; tables var_a var_b ; format var_a fmtvara. var_b fmtvarb. ; run;
or other analysis procedure.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.