BookmarkSubscribeRSS Feed
Flip
Fluorite | Level 6
"wouldn't it be possibel to assign the counter j inside the data steps to n, and then name my variables Var_&n? "

NO because n is not &n

Use an array to create your variables and forget about creating and using macro variables to do this. You are making a simple situation much to complex.

var_(j) = assignment;
will do the job. You simply do not need the macros here.
Cynthia_sas
SAS Super FREQ
In addition to the other suggestions, for more information on how to use ARRAYS to create and populate variables in a SAS program, this paper is very useful:
http://support.sas.com/rnd/papers/sgf07/arrays1780.pdf

cynthia
SAS_user
Calcite | Level 5
sorry i didn't mention it was not a macro loop.

Flip is right, you can not create a new macro variable in datastep when trying to use %let statement.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Useful reading on the subject:


SAS Macro Language: Reference, Scopes of Macro Variables
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a002047080.htm

Scott Barry
SBBWorks, Inc.
abdullala
Calcite | Level 5
%eval is confused by one macro variable &m and one SAS dataset variable i.

the easiest way out is not to use %eval:

%let j=&m+i;
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
You Go Cynthia!
Flip
Fluorite | Level 6
The OP error is due to the fact that the %eval is compile time. At that point i is 'i' not the value of the datastep variable i.

It leads to other confusion of using macro variables for program flow within a datastep when they are not needed. It is much better to use datastep variables to control loops within the datastep whenever possible. My feeling is that this all could be done without the use of macros, except for the repitition of the datastep itself.
SUN59338
Obsidian | Level 7
I believe that you can't assign a macro variable a value with a data set variable, because the macro statements will be compiled to generate open code value or statements before the data set statements were executed.
So p=&m+i will work, and after complied, this will be converted to a open code statement with a real value of macro variable m, ie. p=3+i;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 22 replies
  • 12222 views
  • 1 like
  • 7 in conversation