DATA Step, Macro, Functions and more

dummy variables

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 142
Accepted Solution

dummy variables

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!!

 


Accepted Solutions
Solution
‎02-24-2016 04:12 PM
Super User
Posts: 19,868

Re: dummy variables

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


All Replies
Solution
‎02-24-2016 04:12 PM
Super User
Posts: 19,868

Re: dummy variables

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;
Trusted Advisor
Posts: 1,118

Re: dummy variables

Or a bit shorter:

data want;
set have;
ER=(admsrc='0' | admtype='1' | typsvc1='K' | appttype_r='EROOM' | ppsprod='01');
run;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

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