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

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

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.

 

 

 

View solution in original post

3 REPLIES 3
Shmuel
Garnet | Level 18

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.

 

 

 

ballardw
Super User

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.

RandyStan
Fluorite | Level 6
Thank you so much

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 3 replies
  • 775 views
  • 3 likes
  • 3 in conversation