The SAS Output Delivery System and reporting techniques

Conditional usage of macros

Reply
N/A
Posts: 0

Conditional usage of macros

I am newbie to SAS.
Basically, I have written a few macros in SAS which I would like to activate when different conditons are met.
For example ,I have a do loop and I would like diff macros to be called each time the do loop is incremented.


(Toggle Plain Text)
Data _NULL_

Do i=0 to 10

Select (i)

When (0)%Macro1(var1);
when(2) % macro2(var2);
....
otherwise
end
end
Data _NULL_

Do i=0 to 10

Select (i)

When (0)%Macro1(var1);
when(2) % macro2(var2);
....
otherwise
end
end


However, I found that I cannot do that i.e. select different macros when different conditions are met. Anybody can suggest how I could achieve the same functionality?


Also, is it possible to concatenate 2 macro strings.

i.e. % Let macro1=ABC;
%Let macro2=DEF;

I would like to have
%Let macro 3= ABCDEF; (but using macro1 and 2 since the values may change.)

How can I do this??
Thanks.

(P.S if possible, do explain using code fragments as i am really very new to SAS and may not be aware of some of the "basic"rules of the language)
SAS Super FREQ
Posts: 8,862

Re: Conditional usage of macros

Posted in reply to deleted_user
Hi:
This question isn't about ODS or Base Reporting Procedures (PRINT, REPORT and TABULATE).

There is no better documentation on Macro processing than the Macro reference in the documentation, the SUGI and SGF papers that have been written and the books by users on the topic of macro.

This forum posting, in particular, answers your second question about concatenating macro variables together:
http://support.sas.com/forums/thread.jspa?messageID=7694Ḏ

Your first question (about executing code conditionally using macro processing), besides being off-topic is WAY too big a topic to cover here in the forum.

Here are some links to other forums postings that you may find useful:
http://support.sas.com/forums/thread.jspa?messageID=7089᮱
http://support.sas.com/forums/thread.jspa?messageID=6402ᤂ
http://support.sas.com/forums/thread.jspa?messageID=5697ᙁ

This SUGI paper is particularly helpful:
http://www2.sas.com/proceedings/sugi28/056-28.pdf

For more help, you might consider contacting SAS Tech Support.

cynthia
Ask a Question
Discussion stats
  • 1 reply
  • 313 views
  • 0 likes
  • 2 in conversation