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

Does anyone know a way to convert the MS Access iif function to a case statement *in bulk*?

 

I'm converting Access apps to SAS and found one with dozens of iif statements and I thought it would be 'fun' (sick, yes, I know) to try to come up with a way to take this:

 

IIf(MEPE_ELIG_IND="Y",MEME_LAST_NAME,Null)

 

and write a macro so that I could simply do this:

 

%IIf(MEPE_ELIG_IND="Y",MEME_LAST_NAME,Null)

 

that would convert that to 

case when MEPE_ELIG_IND="Y" then MEME_LAST_NAME else Null end

I thought I'd be clever and just come up with something like this:

 

%macro iif(condition,true,else);
case when &condition then &true else &else end
%mend iif;

 

But, of course, SAS considers MEPE_ELIG_IND="Y" to be passing a value to the macro variable MEPE_ELIG_IND instead of a whole value for variable &condition.

Just wondered if anybody had ideas for this.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Why not just use the IFN() or IFC() functions instead of making a macro?

View solution in original post

5 REPLIES 5
Tom
Super User Tom
Super User

Either include the parameter name in the call:

%IIf(CONDITION=MEPE_ELIG_IND="Y",MEME_LAST_NAME,Null)

Or add parentheses around the condition.

%IIf((MEPE_ELIG_IND="Y"),MEME_LAST_NAME,Null)

Or both.

Tom
Super User Tom
Super User

Why not just use the IFN() or IFC() functions instead of making a macro?

tomrvincent
Rhodochrosite | Level 12
Doh! That did the trick! Thanks so very much!
Kurt_Bremser
Super User

Since

%IIf(MEPE_ELIG_IND="Y",MEME_LAST_NAME,Null)

takes longer to write than

ifc(MEPE_ELIG_IND="Y",MEME_LAST_NAME,"")

I really see no value in creating a macro.

tomrvincent
Rhodochrosite | Level 12
And if I'd remembered IFC I wouldn't have posted the question. No value indeed.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 690 views
  • 5 likes
  • 3 in conversation