The SAS Output Delivery System and reporting techniques

How to create a macro variable from interactive macro variables?

Posts: 0

How to create a macro variable from interactive macro variables?

I'm working on an interactive query system and I need help:

I have several macro variables that will be passed on from the query interface when a user makes a multiple-year selection for the year variable. The system will create the following macro variables:

%let year0=4;
%let year=1;
%let year1=1996;
%let year2=1998;
%let year3=2001;
%let year4=2005;

The number and values of the macro variables above may be different at different times. For instance, for a different query that is submitted, the macro variables could be as follows:

%let year0=3;
%let year=1;
%let year1=1996;
%let year2=1997;
%let year3=2002;

For example, I want to create a new macro variable (named "yearnew") that has a value of (1996,1998,2001,2005) for the first query submitted to our system but then the value of the macro variable for the second query submitted would be: (1996,1997,2002)

So I plan to create this “yearnew” macro variable so that I can use it in a subsequent macro program.

Thanks a million for your help.
Posts: 9,100

Re: How to create a macro variable from interactive macro variables?

Posted in reply to deleted_user
This isn't really an ODS or BASE Reporting Procedure question. However, here's a quick example to point you in the right direction.

To concatenate macro variables together, you would do something like this:
*** concatenate macro variable example;

%let one = kermit;
%let two = the;
%let three = frog;

%put ******** check resolution **********;
%put one=&one two=&two three=&three;

%let phrase = &one &two &three;
%let alt = &one, &two$ &three!!!;

%put ******** check resolution **********;
%put phrase=&phrase alt=&alt;


And then in the SAS log, you will see the following:
499 *** concatenate macro variable example;
501 %let one = kermit;
502 %let two = the;
503 %let three = frog;
505 %put ******** check resolution **********;
******** check resolution **********
506 %put one=&one two=&two three=&three;
one=kermit two=the three=frog
508 %let phrase = &one &two &three;
509 %let alt = &one, &two$ &three!!!;
511 %put ******** check resolution **********;
******** check resolution **********
512 %put phrase=&phrase alt=&alt;
phrase=kermit the frog alt=kermit, the$ frog!!!


Note how the punctuation (, $ !!!) in the %let statement:
%let alt = &one, &two$ &three!!!;
gets put into the new macro variable &ALT:
alt=kermit, the$ frog!!!

For more help with this task, for example, using a MACRO %DO loop or using %IF or writing a macro program to automatically validate and build your new macro variable, your best bet for help is to read the SAS Macro documentation or to contact Tech Support:

Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation