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: 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
  • 5 replies
  • 683 views
  • 0 likes
  • 4 in conversation