BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi
I am wanting to assign different macro variables to an array. With help from this forum, I have the assignment of the macro variable working in principle. However, I would like to change which macro variables are assigned to this array (i.e. "&adjust0904 &adjust0906" in the sample code below). I cannot figure out the code to get this working. Any ideas? Thanks!

%Macro Survey(Months);

%Let adjust0904 = 1.1;
%Let adjust0905 = 1.2;
%Let adjust0906 = 1.3;

Data B;
Set survey;

* &Months should be incorporated some how to provide the code below: ;
array aj{2} _temporary_ (&adjust0904 &adjust0906);

Do i = 1 to 2;
...code...
End;
Run;
%Mend;
%Survey (0904 0905);
3 REPLIES 3
Cynthia_sas
SAS Super FREQ
Hi:
You will want to read about referencing macro variables "indirectly", as explained in this documentation topic:
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a001071915.htm

Basically, the way you reference macro variables indirectly is to allow a "final" string to be resolved from multiple macro variable references. Consider the macro program at the bottom of this posting for an example of indirect macro references.

These papers may also be useful to you:
http://www2.sas.com/proceedings/sugi29/128-29.pdf
http://www2.sas.com/proceedings/sugi22/CODERS/PAPER77.PDF
http://www.lexjansen.com/sugi/sugi21/bt/054-21.pdf
http://www.ats.ucla.edu/stat/sas/library/nesug98/p086.pdf
http://www.nesug.org/Proceedings/nesug97/posters/gerlach.pdf
http://studysas.blogspot.com/2009/02/3when-to-use-do-we-distinguishmultiple.html

cynthia

[pre]
%let fav = muppet;
%let muppet1 = kermit;
%let muppet2 = elmo;
%let muppet3 = big bird;

%macro listmup2;
%do i = 1 %to 3;
%put My favorite &fav number &i is: &&muppet&i;
%put Alternate: My favorite &fav is: &&&fav&i;
%end;
%mend listmup2;

%listmup2;
[/pre]
Flip
Fluorite | Level 6
You can parse the incoming parameter then append it to the root of your macro variable.

%macro survey( parm);

%Let adjust0904 = 1.1;
%Let adjust0905 = 1.2;
%Let adjust0906 = 1.3;


%let i = 1;
%do %while (%scan(&parm, &i, ' ') ^= );
%let cd = %scan(&parm, &i, ' ');
%put &&adjust&cd;
%let i = %eval(&i + 1);
%end;
%mend;
%survey(0904 0906);
deleted_user
Not applicable
This is fantastic - thanks to you both!! The following code in the data step does the trick:
[pre]
%let adjust = ;

%let i = 1;
%do %while (%scan(&parm, &i, ' ') ^= );
%let cd = %scan(&parm, &i, ' ');
%let adjust = &adjust &&adjust&cd;
%put &adjust;
%let i = %eval(&i + 1);

%end;

array aj{3} _temporary_ (&adjust);
[/pre]

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 3 replies
  • 592 views
  • 0 likes
  • 3 in conversation