BookmarkSubscribeRSS Feed
ly2105
Fluorite | Level 6

Hello, 

 

I would like to create a new variable YBIN based on my continuous variable Y for use in a regression model. Y is a continuous variable that ranges from 21 to 266 with units of 1 (eg, possible values can be 21, 22, 45, 66, 109... etc) . For interpretation, I would like to bin this variable into lengths of 10 such that the new variable YBIN is 1=20-30, 2=31-40, 3=41-50, 4=51-60... and so on, up to 270. A value of 266 would fall into the bin of 261-270. 

 

I've tried proc rank and proc hpbin, but it doesn't seem like either allows you to select the width of your bin (only the number of total bins). 

I've also looked at this but don't fully understand the do loop. https://communities.sas.com/t5/SAS-Programming/binning-a-continuous-variable-for-further-analysis/m-...

 

Thanks! 

 

 

Thanks! 

3 REPLIES 3
PaigeMiller
Diamond | Level 26
ybin = floor((y-1)/10) - 1;
--
Paige Miller
ly2105
Fluorite | Level 6
Thanks- what is the purpose of subtracting 1?
PaigeMiller
Diamond | Level 26

In your original statement of the problem, you said you wanted

 

1=20-30, 2=31-40, 3=41-50, 4=51-60

 

If you don't subtract 1, you don't get these values. Although, from a purely practical point of view, subtracting 1 shouldn't affect the regression you are going to do, and so subtracting 1 could be omitted without any negative effects.

--
Paige Miller

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 855 views
  • 0 likes
  • 2 in conversation