- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
For that, you just need to add quotes:
if "&ClientCode" = .....
They have to be double-quotes, not single-quotes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Ah...I see...that was a typo. It would not be dependent on Response...ONLY ClientCode.
Sorry.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
For that, you just need to add quotes:
if "&ClientCode" = .....
They have to be double-quotes, not single-quotes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
OMG I knew it was something simple. Was way overthinking it! Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.