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
For that, you just need to add quotes:
if "&ClientCode" = .....
They have to be double-quotes, not single-quotes.
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 ?
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
Ah...I see...that was a typo. It would not be dependent on Response...ONLY ClientCode.
Sorry.
For that, you just need to add quotes:
if "&ClientCode" = .....
They have to be double-quotes, not single-quotes.
OMG I knew it was something simple. Was way overthinking it! Thank you!
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.
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.
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.