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

I have a macro program that I've written that uses multiple parameters. 

 

One of these parameters is the clients' name. The macro looks something like this:

 

 


%macro  Program(
CampaignCode,
ClientCode,
Start,
End,
Response
)

 

 

The commands that are called using the macro are pages and pages long but there is a certain place where I want to create a set of conditional statements for calculations based on the value of &ClientCode

 

Basically something like this

 

data work.want;

set work.have;

if &ClientCode = "Client1" then Calculation = VAR1 +VAR2+VAR3;

else if &ClientCode= "Client2" then Calculation = VAR1 + VAR3 + VAR4;

else if &ClientCode = "Client3" then Calculation = Var2 + VAR4 + VAR6;

.....;

run;

 

But that is not working correctly. 

 

I feel like this is a relatively simple command I am trying to execute. Can someone show me the correct synthax? 

 

Thanks

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

For that, you just need to add quotes:

 

if "&ClientCode" = .....

 

They have to be double-quotes, not single-quotes.

View solution in original post

6 REPLIES 6
Astounding
PROC Star

How do these calculations depend on the value of &Response ?

 

The correct syntax depends on what is contained in the macro variables.  In particular, what is the value for &ClientCode ?

SmcGarrett
Obsidian | Level 7

The Value would be a string of 4 characters that are a code for the client. 

 

Some clients calculate their total budget based on different combinations of Variables

 

 

SmcGarrett
Obsidian | Level 7

Ah...I see...that was a typo. It would not be dependent on Response...ONLY ClientCode. 

 

Sorry.

Astounding
PROC Star

For that, you just need to add quotes:

 

if "&ClientCode" = .....

 

They have to be double-quotes, not single-quotes.

SmcGarrett
Obsidian | Level 7

OMG I knew it was something simple. Was way overthinking it! Thank you! 

 

Tom
Super User Tom
Super User

Not sure what RESPONSE has to do with your question as the code you posted is referencing the parameter CLIENTCODE instead.

So code like this:

data work.want;
  set work.have;
  if &ClientCode = "Client1" then Calculation = VAR1 +VAR2+VAR3;
  else if &ClientCode= "Client2" then Calculation = VAR1 + VAR3 + VAR4;
  else if &ClientCode = "Client3" then Calculation = Var2 + VAR4 + VAR6;

Will work you you set CLIENTCODE equal to something that evaluates to a character string.  So you could call it with a string literal.

%program(clientcode="Client2",...)

Or you could call it with the name of a character variable that is in the HAVE dataset.

%program(clientcode=Client_Id,...)

Or even a function call that can run in the generated IF statement as long it the result is a character string that the IF statement can compare to the literal character values.

 

 

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