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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 22 replies
  • 11143 views
  • 1 like
  • 7 in conversation