## Resolve a series of macro variables

Solved
Occasional Contributor
Posts: 12

# Resolve a series of macro variables

Hello, I want to resolve a series of macro variables in a do loop, but the following program doesn't work. For some reason, I can't

define the array for mac1-mac3. Any idea on how to resolve them directly?

%let mac1=2;
%let mac2=3;
%let mac3=7;
data test;
array gg{3} gg1-gg3 ;
do i=1 to 3;
gg{i}=dequote(cats('&','mac',put(i,best.)));
end;
run;

Accepted Solutions
Solution
3 weeks ago
Super User
Posts: 10,761

## Re: Resolve a series of macro variables

``````%let mac1=2;
%let mac2=3;
%let mac3=7;
data test;
array gg{3} gg1-gg3 ;
do i=1 to 3;
gg{i}=symgetn(cats('mac',i));
end;
run;``````

All Replies
Solution
3 weeks ago
Super User
Posts: 10,761

## Re: Resolve a series of macro variables

``````%let mac1=2;
%let mac2=3;
%let mac3=7;
data test;
array gg{3} gg1-gg3 ;
do i=1 to 3;
gg{i}=symgetn(cats('mac',i));
end;
run;``````
Occasional Contributor
Posts: 12

## Re: Resolve a series of macro variables

I appreciate your help, Ksharp. This is the second time you help me in time. Thanks so much.
Super User
Posts: 9,599

## Re: Resolve a series of macro variables

Why would you put numerical data into character macro variables, then write a datastep to put them into a series of numerical variables in a dataset using implicit conversion?  The whole process seems bizarre?

```data test;
gg1=1;
gg2=2;
gg3=3;
run;```

This is effectively what the code does?

Occasional Contributor
Posts: 12

## Re: Resolve a series of macro variables

The reason is that I calculate those macro variables in the earlier step and want to use them in later data step. My real program is like
data want;
set one;
Impose the do loop on set one(include that series of macro variables)
That might be bizarre for you, but as a fresh sas man, I can't come up with a better idea.
Super User
Posts: 10,209

## Re: Resolve a series of macro variables

@liyongkai800 wrote:
The reason is that I calculate those macro variables in the earlier step and want to use them in later data step. My real program is like
data want;
set one;
Impose the do loop on set one(include that series of macro variables)
That might be bizarre for you, but as a fresh sas man, I can't come up with a better idea.

Anytime you have a series of data, consider to store it in a dataset. If you need it for look-up purposes, create a format from that dataset.

I basically only store singular pieces of data (like a cutoff date, or a company descriptor for filtering) in macro variables.

Think like that: the macro preprocessor helps you in making code dynamic. It is not designed (or meant) for handling data.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 9,599

## Re: Resolve a series of macro variables

Just to add to that, you also use the ability to merge/join data as well.

Super User
Posts: 8,069

## Re: Resolve a series of macro variables

So if you have single observation dataset with those three variables you can include into a future and there is no need to move the values into macro variables at all.

Say you have the values in a dataset name SUMMARY and you want to combine that with another dataset named HAVE to produce a dataset named WANT.  You might code something like this:

``````data want ;
if _n_=1 then set summary ;
set have ;
* Calculations using variables from HAVE and SUMMARY ;
run;``````

SAS will automatically retain the values of the variables from SUMMARY onto all iterations of the data step.

Occasional Contributor
Posts: 12

## Re: Resolve a series of macro variables

Thanks, I will take that for later program.
☑ This topic is solved.