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

I'm having an issue with if statements in terms of which if statement takes precedence when the similar conditions are met. Let me explain. This is my data:

 

data MACID;
  input ApprovedPriceType $ 'GER Pharm'n $ Instate $ Code_MAC $;
datalines;
MAC2501A CVS MACHZ .
MAC5251A CVS MACHZ MAC01
MACCHPCO CVS MACHZ MAC02
MACCHPME CVS MACHZ MACMEDCARE
MACHZ CVS MACJX .
MACIA CVS MACJX MAC01
MACNC CVS MACJX MACMEDCARE
;

And this is my code:

 

data MACLIST;
  set MACID;
if ApprovedPriceType in('MAC5251A','MACCHPCO','MACHZ','MACNC') then MAC_List=ApprovedPriceType;
if 'GER Pharm'n='CVS' and Instate='MACHZ' and Code_MAC='MAC02' then MAC_List='MAC02';
if 'GER Pharm'n = 'CVS' and Instate = 'MACHZ' and Code_MAC='MAC01' then MAC_List='MAC2501A1J';
run;

What I'm trying to do with the first if statement is make it have precedence over any proceeding if statement. So, for example, if the ApprovedPriceType is 'MACCHPCO', I want the MAC_List to be 'MACCHPCO'. The trouble is, once it hits the second if, which matches the conditions of the 'MACCHPCO' line in the data, I get 'MAC02' as the MAC_List. Why is this? I tried flipping the lines and it still didn't work. How can I fix this? Thank you for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
Loko
Barite | Level 11

Hello,

 

Use else if for the 2nd and third statement.

View solution in original post

1 REPLY 1
Loko
Barite | Level 11

Hello,

 

Use else if for the 2nd and third statement.

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
  • 1 reply
  • 676 views
  • 1 like
  • 2 in conversation