BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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.
1 REPLY 1
Cynthia_sas
SAS Super FREQ
Hi:
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:
[pre]
*** 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;

[/pre]

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

[/pre]

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

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: http://support.sas.com/techsup/contact/index.html

cynthia

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 1 reply
  • 580 views
  • 0 likes
  • 2 in conversation