BookmarkSubscribeRSS Feed
Mirisage
Obsidian | Level 7
Hi Colleagues,

Would appreciate if any one of you could help me.

I have a data set like this.

Data hs;
Input ID food_run;
CARDS;
1 1
2 2
3 3
4 3
5 2
6 1
7 7
8 8
9 9
;
RUN;

In food-run variable,
1=often true
2=sometimes true
3=never true
4=don’t know
5=refusal
6=not stated

I need to create a new variable called WORRIED like this.

If the response for variable food_run = 1 or 2 then WORRIED=1
If the response for variable food_run = 3 then WORRIED=2
If the response for variable food_run = 4 or 5 or 6 then WORRIED=missing or .

I attempted like this but this does not work properly.
Data hs1;
Set hs;
If food_run = 1 or 2 then WORRIED=1;
If food_run = 2 then WORRIED=2;
Else WORRIED=.;
Run;

Could you please assist to write the correct program.

Thanks

Mirisage
4 REPLIES 4
Flip
Fluorite | Level 6
If food_run = 1 or 2 should be if food_run in(1,2); or
If food_run = 1 or food_run = 2;
Mirisage
Obsidian | Level 7
Hi Flip,

Thank you very much.

I tried your both suggestions but they didn't work. However, I removed the statement 'else .' and then both of your suggestions worked well.

Hope it is not an accident and it should be the way, isn't it?

Data hs1;
Set hs;
If food_run =1 or food_run= 2 then WORRIED=1;
If food_run = 3 then WORRIED=2;

Run;


Data hs1;
Set hs;
If food_run in(1,2)then WORRIED=1;
If food_run = 3 then WORRIED=2;

Run;


thank you

Mirisage
Flip
Fluorite | Level 6
use an else if for the second one.

else If food_run = 2 then WORRIED=2;
Mirisage
Obsidian | Level 7
Hi Flip, this is great!

Worked very well.

Thanks again!

Mirisage Neil

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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