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

I'm creating some dummy variables for analysis, and I need help with a step...

I have four different variables that indicate an ER visit, if coded a specfic value (all different values).  So I have this first part:

 

data want;

set have;

if admsrc='0' then ER=1;

if admtype='1' then ER=1;

if typsvc1='K' then ER=1;

if appttype_r='EROOM' then ER=1;

if ppsprod='01' then ER=1;

run;

 

but how to I set the rest of the ER values to 0?  I tried adding the 'else ER=0' at the end, but that didn't output the values correctly.

 

Thanks for your assistance!!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Use IF/ELSE IF/ELSE rather than listing individual IF statements. 

In a block as below, the first condition that is evaluated as true and then the rest are NOT tested.

Otherwise, each condition is tested and can set the value. 

data want;
set have;
if admsrc='0' then ER=1;
else if admtype='1' then ER=1;
else if typsvc1='K' then ER=1;
else if appttype_r='EROOM' then ER=1;
else if ppsprod='01' then ER=1;
else ER=0;
run;

View solution in original post

2 REPLIES 2
Reeza
Super User

Use IF/ELSE IF/ELSE rather than listing individual IF statements. 

In a block as below, the first condition that is evaluated as true and then the rest are NOT tested.

Otherwise, each condition is tested and can set the value. 

data want;
set have;
if admsrc='0' then ER=1;
else if admtype='1' then ER=1;
else if typsvc1='K' then ER=1;
else if appttype_r='EROOM' then ER=1;
else if ppsprod='01' then ER=1;
else ER=0;
run;
FreelanceReinh
Jade | Level 19

Or a bit shorter:

data want;
set have;
ER=(admsrc='0' | admtype='1' | typsvc1='K' | appttype_r='EROOM' | ppsprod='01');
run;

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!

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