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

Hi, from raw data I have always found 1,2,3, likewise but in this particular reserch question in raw data 101-199, 201-299, 888! If I use the below code I get only raw data 888 results because this code only worked not the 101-199 or 201-299. How do I fix that?

 

This is the code I have used to categorize the raw data as 1,2,3This is the code I have used to categorize the raw data as 1,2,3Result! Frequency missingResult! Frequency missing

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
if alcday5 = 101-199 then ...

one hundred one minus one hundred ninety nine is negative 98 (that's how the minus sign is interpreted in this code in SAS)

 

So this code is not doing what you want it to do, since alcday5 is never equal to –98

 

You probably want this:

if 101<=alcday5<=199 then ...
--
Paige Miller

View solution in original post

5 REPLIES 5
Reeza
Super User
101 - 199 is 99 so you're checking if your value is 99.

I think you want:

if alcday5 in (101:199) then alcohol = 3;

OR

if alcday5 >= 101 and alcday5 <=199 then alcohol = 3;

Please post code as text not images in the future.
zahidhasandipu
Calcite | Level 5

I figured it out! 

if 101<=alcday5<=199 then alcohol = 3;
if 201<=alcday5<=299 then alcohol = 2;
if alcday5 = 888 then alcohol = 1;

 

PaigeMiller
Diamond | Level 26
if alcday5 = 101-199 then ...

one hundred one minus one hundred ninety nine is negative 98 (that's how the minus sign is interpreted in this code in SAS)

 

So this code is not doing what you want it to do, since alcday5 is never equal to –98

 

You probably want this:

if 101<=alcday5<=199 then ...
--
Paige Miller
zahidhasandipu
Calcite | Level 5
Yep, exactly! Thank you
ballardw
Super User

And for the $64,000 question, WHAT interpretation is Alcohol=2? and Alcohol=3?

 

The question reads like an assignment so I won't argue with the coding but the use is a completely different matter.

 

If it is supposed to be a "severity" measure then you may want to consider which is more "severe" 1 drink per week (101) or 99 drinks per month (299)?

 

If the source is as I think, then wait until you try to reconcile the "drinks per occasion" with the other related variables.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 5 replies
  • 776 views
  • 0 likes
  • 4 in conversation