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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1813 views
  • 0 likes
  • 2 in conversation