<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Accessing variable condition on macro variable value in loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Accessing-variable-condition-on-macro-variable-value-in-loop/m-p/60164#M12997</link>
    <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your reply. The programs you display are somewhat similar to what I need to achieve; I think the one below does the actual calculation I want in the array format that you recommend. &lt;BR /&gt;
&lt;BR /&gt;
Nonetheless, the first issue I really need to resolve before I can continue is how to use the value of a variable (in my case, the value of the variable "flight_counter") to call up another variable to be changed (with the prefix ac_cat_, and a suffix dependent on "flight_counter". So, for example, when flight_counter = 1, I need to insert the value of "n" into the variable "ac_cat_1" ; when flight_counter = 2, insert the value of "n" into "ac_cat_2" ; and so on. The set of variables prefixed "ac_cat_" is created, and filled with ".". I need a statement before the end of the "if" statement to populate the appropriate "ac_cat_" variable with the value of "n". For now, I have inserted the line "ac_cat_1 = n;", but the "1" needs to be changed to a reference to the value of "flight_counter". This is the information that I absolutely need to store from the output of the process below. As I mentioned in an earlier post, I would eventually like to use a "do while" loop, changing "condition" at the end of each turn of the loop, such that the process is repeated until "condition" reaches 0. This will require "flight_counter" to increase an unknown number of times.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data mydata_out; set mydata ;&lt;BR /&gt;
flight_counter = 0;&lt;BR /&gt;
empty_seat_counter = sgmt_empty_seats;	&lt;BR /&gt;
remaining_pass_counter = add_passenger_demand;		&lt;BR /&gt;
condition = remaining_pass_counter &amp;gt;= .25*empty_seat_counter;	&lt;BR /&gt;
&lt;BR /&gt;
if condition = 1 then do; &lt;BR /&gt;
	drop i ;&lt;BR /&gt;
	flight_counter = flight_counter + 1;&lt;BR /&gt;
	array cum_p {0:6}  cum_p_0 - cum_p_6;&lt;BR /&gt;
	array lf {0:6} load_factor_0 - load_factor_6;&lt;BR /&gt;
	array choose{0:6};&lt;BR /&gt;
&lt;BR /&gt;
	do i = 0 to 6 ;&lt;BR /&gt;
		x = uniform(-1)  ;&lt;BR /&gt;
		choose{i} = x &amp;gt;= cum_p{i} ;&lt;BR /&gt;
	end;&lt;BR /&gt;
	n = n = sum(of choose{*}); &lt;BR /&gt;
&lt;BR /&gt;
	load_factor_chosen = lf{n} ;&lt;BR /&gt;
	ac_cat_1 = n;&lt;BR /&gt;
&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;U&gt;&lt;/U&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I realize that I have quite a bit to learn about macros the details of SAS processing, and that seems to have ignited a bit of indignation.....However, I would really appreciate if someone could provide insight into this particular issue (which is probably quite simple), since figuring that out is crucial for me.&lt;B&gt;&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
Thanks very much, &lt;BR /&gt;
R.&lt;BR /&gt;
&lt;BR /&gt;
I am going to repost this message under a new thread, since my current question has little to do with the initial issue.&lt;BR /&gt;
 &lt;BR /&gt;
Message was edited by: rdwest</description>
    <pubDate>Sat, 08 Jan 2011 19:12:10 GMT</pubDate>
    <dc:creator>rdwest</dc:creator>
    <dc:date>2011-01-08T19:12:10Z</dc:date>
    <item>
      <title>Accessing variable condition on macro variable value in loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Accessing-variable-condition-on-macro-variable-value-in-loop/m-p/60160#M12993</link>
      <description>Hello, &lt;BR /&gt;
&lt;BR /&gt;
I'm having trouble with the last several lines of the macro I'm attempting to build. For each observation in my data set, the macro chooses a category "n" (0 through 6) based on the outcome of a random number draw. The last several lines access variables whose suffix depends on that category (e.g., "load_factor_2" or "seats_per_plane_2", etc.). &lt;BR /&gt;
&lt;BR /&gt;
Before doing the intended calculations using these variables, I've temporarily inserted two lines to find out whether the correct values are being accessed using the suffix "n". What actually seems to be happening is that for every observation, "&amp;amp;n" as a suffix resolves to 0, and the value of "n" itself is added to that. So in a case where n = 2, load_factor_test calculates load_factor_0 + 2.  The value of load_factor_0 is correctly accessed for that observation.....but I don't understand what's prompting the addition. And I'm at a loss for how to get access to the value of load_factor_2. (I've also tried inserting the value into a macro variable, and tried _&amp;amp;&amp;amp;n as a suffix, in case this is necessary. Both produce the same result.) &lt;BR /&gt;
&lt;BR /&gt;
I'm sure there are much more expeditious ways to design this entire piece of code, but this is what I've come up with. Eventually, I'd like to translate the "do" loop dependent on the value of "condition" into a "do while" loop (so that "condition" is recalculated and the loop is run until it reaches 0), but I'm having trouble with the simpler step first. &lt;BR /&gt;
&lt;BR /&gt;
Any help would be greatly appreciated.&lt;BR /&gt;
&lt;BR /&gt;
%macro test;&lt;BR /&gt;
Data FOS.ACChoiceModelTest; set out_scores;&lt;BR /&gt;
%let cum_p = 0;&lt;BR /&gt;
%do i = &amp;amp;min %to &amp;amp;max;&lt;BR /&gt;
	cum_p_&amp;amp;i = &amp;amp;cum_p + P_&amp;amp;i;													/* Calculate cumulative probabilities */&lt;BR /&gt;
	%let cum_p = &amp;amp;cum_p + P_&amp;amp;i;&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
%do i = 1 %to 10;&lt;BR /&gt;
	ac_cat_&amp;amp;i = .;																/* Create empty variables to hold new aircraft selections */&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
%let flight_counter = 0;														/* Initialize counter: the number of added flights */&lt;BR /&gt;
empty_seat_counter = sgmt_empty_seats;											/* Initialize counter: the number of empty (available) seats */&lt;BR /&gt;
remaining_pass_counter = add_passenger_demand;									/* Initialize counter: the number of passengers not yet emplaned */			&lt;BR /&gt;
condition = remaining_pass_counter &amp;gt;= .25*empty_seat_counter;					/* Starting condition for adding flight */&lt;BR /&gt;
&lt;BR /&gt;
if condition = 1 then do; &lt;BR /&gt;
	%let flight_counter = %eval(&amp;amp;flight_counter + 1);							/* Add a flight */						&lt;BR /&gt;
	%let rand = uniform(-1);													/* Random number draw */&lt;BR /&gt;
	rand = &amp;amp;rand;&lt;BR /&gt;
	%let n = 0;&lt;BR /&gt;
	%do i = 0 %to 6;							&lt;BR /&gt;
		%let n = &amp;amp;n + (rand &amp;gt;= cum_p_&amp;amp;i);										/* Use the random number draw to find the chosen SC category */																		&lt;BR /&gt;
	%end;&lt;BR /&gt;
	ac_cat_&amp;amp;flight_counter = &amp;amp;n;												/* Record the AC choice in a permanent variable */&lt;BR /&gt;
&lt;BR /&gt;
	load_factor_test = load_factor_&amp;amp;n;&lt;BR /&gt;
	seats_per_plane_test = seats_per_plane_&amp;amp;n;&lt;BR /&gt;
&lt;BR /&gt;
	remaining_pass_counter = remaining_pass_counter - (load_factor_&amp;amp;n * seats_per_plane_&amp;amp;n);		/* Recalculate remaining passengers */&lt;BR /&gt;
	empty_seat_counter = sgmt_empty_seats + (1 - (load_factor_&amp;amp;n * seats_per_plane_&amp;amp;n));			/* Recalculate empty seats */&lt;BR /&gt;
	condition = remaining_pass_counter &amp;gt;= .25*empty_seat_counter;									/* Recalculate condition for loop */&lt;BR /&gt;
end; &lt;BR /&gt;
	&lt;BR /&gt;
run; &lt;BR /&gt;
%mend test;&lt;BR /&gt;
%test</description>
      <pubDate>Fri, 07 Jan 2011 14:37:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Accessing-variable-condition-on-macro-variable-value-in-loop/m-p/60160#M12993</guid>
      <dc:creator>rdwest</dc:creator>
      <dc:date>2011-01-07T14:37:12Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing variable condition on macro variable value in loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Accessing-variable-condition-on-macro-variable-value-in-loop/m-p/60161#M12994</link>
      <description>Hi:&lt;BR /&gt;
  Do you have a working, non-macroized SAS program that produces what you want?? I mean a program without ANY macro %DO loops or &amp;amp;macvar references???&lt;BR /&gt;
&lt;BR /&gt;
  Here's the thing. Remember a few posts back&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/message.jspa?messageID=48254#48254" target="_blank"&gt;http://support.sas.com/forums/message.jspa?messageID=48254#48254&lt;/A&gt;&lt;BR /&gt;
 &lt;BR /&gt;
  When I posted some useful links about macro processing:&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi28/056-28.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi28/056-28.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi29/128-29.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi29/128-29.pdf&lt;/A&gt; (this paper has a good discussion/examples on IF versus %IF)&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi27/p067-27.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi27/p067-27.pdf&lt;/A&gt; (the last sentence in this paper is: "Often in DATA step programming, arrays provide a better answer than macro.")&lt;BR /&gt;
&lt;A href="http://analytics.ncsu.edu/sesug/2006/HW02_06.PDF" target="_blank"&gt;http://analytics.ncsu.edu/sesug/2006/HW02_06.PDF&lt;/A&gt;&lt;BR /&gt;
 &lt;BR /&gt;
and I ended the post by saying:&lt;B&gt;&lt;BR /&gt;
"You also need to REALLY understand the difference between macro program compile, macro program execution phases and do NOT confuse them with DATA step compile and DATA step execution phases."&lt;/B&gt;&lt;BR /&gt;
 &lt;BR /&gt;
The macro facility is going to ONLY, ONLY, ONLY generate code that will be sent forward to the compiler. So, can you tell me what DATA step code you envision being sent to the compiler as a result of this %DO loop and assignment statement from your program??&lt;BR /&gt;
[pre]&lt;BR /&gt;
%let n = 0;&lt;BR /&gt;
%do i = 0 %to 6; &lt;BR /&gt;
%let n = &amp;amp;n + (rand &amp;gt;= cum_p_&amp;amp;i); /* Use the random number draw to find the chosen SC category */ &lt;BR /&gt;
%end;&lt;BR /&gt;
ac_cat_&amp;amp;flight_counter = &amp;amp;n; /* Record the AC choice in a permanent variable */&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
By the time this program gets sent to the compiler ALL the macro variable references and %DO loop and %LET will be gone, resolved, or otherwise, not in the code that the compiler gets. &lt;BR /&gt;
&lt;BR /&gt;
Have you used SYMBOLGEN, MPRINT, MLOGIC options to review the compiled code that has been generated from your macro program??? Is the generated code the same as the working SAS code that you started with (or should have started with)????&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Fri, 07 Jan 2011 15:31:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Accessing-variable-condition-on-macro-variable-value-in-loop/m-p/60161#M12994</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2011-01-07T15:31:24Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing variable condition on macro variable value in loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Accessing-variable-condition-on-macro-variable-value-in-loop/m-p/60162#M12995</link>
      <description>Whew - okay, point taken. I apologize; I hadn't seen your previous post. I've been looking over the documentation you refer to, and I'm working on understanding distinction between how and when macros are processed (versus normal SAS code), and what that means for the process I'm trying to implement..... &lt;BR /&gt;
&lt;BR /&gt;
Backing up and simplifying as you suggest, I separated out the stages, tried to use variables rather than macro variables wherever possible, and omit the loops except where I know they work as intended. (I don't actually know how to avoid using loops in %do / %end form [such as using do / end instead], and these steps function as intended, so I left these in.) &lt;BR /&gt;
&lt;BR /&gt;
I know the first portion of the code (which just generates empty variables for use later, and calculates cumulative probabilities) works, so I've separated that out: &lt;BR /&gt;
&lt;BR /&gt;
%macro c;&lt;BR /&gt;
Data FOS.ACChoiceModelTest; set out_scores;&lt;BR /&gt;
%let cum_p = 0;&lt;BR /&gt;
%do i = &amp;amp;min %to &amp;amp;max;&lt;BR /&gt;
	cum_p_&amp;amp;i = &amp;amp;cum_p + P_&amp;amp;i;													/* Calculate cumulative probabilities */&lt;BR /&gt;
	%let cum_p = &amp;amp;cum_p + P_&amp;amp;i;&lt;BR /&gt;
%end;&lt;BR /&gt;
%do i = 1 %to 10;&lt;BR /&gt;
	ac_cat_&amp;amp;i = .;																/* Create empty variables to hold new aircraft selections */&lt;BR /&gt;
%end;&lt;BR /&gt;
run; &lt;BR /&gt;
%mend c;&lt;BR /&gt;
%c&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
What I'm stuck on now is how to change the value of a variable, or access its values for calculations, if the name of that variable depends upon the value of a macro variable. So in the following code, everything works as intended, except the last two lines. I know that the macro variables "f" and "n" have been successfully initialized, since the variable "test_f" and "test_n" take on the correct values, but I can see from the log that "ac_cat_&amp;amp;f" is read as "ac_cat_", and "load_factor_&amp;amp;n" is read as "load_factor_". Why is it not permitted to use macro variables when referring to an existing variable? I don't understand what I'm doing wrong here..... &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Data FOS.ACChoiceModelTest2; set FOS.ACChoiceModelTest;&lt;BR /&gt;
flight_counter = 0;																/* Initialize counter: the number of added flights */&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
/* do while(condition = 1) ; */&lt;BR /&gt;
if condition = 1 then do ;&lt;BR /&gt;
&lt;BR /&gt;
	flight_counter = flight_counter + 1;										/* Add a flight */						&lt;BR /&gt;
	n = 0;																		/* Variable to store the chosen AC category */&lt;BR /&gt;
																				&lt;BR /&gt;
	%let rand = uniform(-1);													/* Random number draw */&lt;BR /&gt;
&lt;BR /&gt;
	%macro d;&lt;BR /&gt;
		%do i = 0 %to 6;							&lt;BR /&gt;
			n = n + (&amp;amp;rand &amp;gt;= cum_p_&amp;amp;i);										/* Use the random number draw to find the chosen SC category */																		&lt;BR /&gt;
		%end;&lt;BR /&gt;
	%mend d;&lt;BR /&gt;
	%d&lt;BR /&gt;
&lt;BR /&gt;
	call symput('f', flight_counter);											&lt;BR /&gt;
	call symput('n', n);&lt;BR /&gt;
	test_f = &amp;amp;f;&lt;BR /&gt;
	test_n = &amp;amp;n;&lt;BR /&gt;
&lt;BR /&gt;
	ac_cat_&amp;amp;f = n;&lt;BR /&gt;
	load_factor_test = load_factor_&amp;amp;n;&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Thank you very much for your help, Cynthia.</description>
      <pubDate>Fri, 07 Jan 2011 19:52:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Accessing-variable-condition-on-macro-variable-value-in-loop/m-p/60162#M12995</guid>
      <dc:creator>rdwest</dc:creator>
      <dc:date>2011-01-07T19:52:18Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing variable condition on macro variable value in loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Accessing-variable-condition-on-macro-variable-value-in-loop/m-p/60163#M12996</link>
      <description>Hi:&lt;BR /&gt;
  You still have not simplified your code to the point where &lt;U&gt;no&lt;/U&gt; %DO loops (zip, nada, none, nary a one) are included. If you have to type 6 or 7 assignment statements to understand what your program needs to look like, then type them. You really, really need to understand the code that needs to be generated. I am still not convinced that you need a Macro program. I think you may be confusing iterative ARRAYS and numbered variables with MACRO %DO loops. &lt;BR /&gt;
 &lt;BR /&gt;
  Also, do you understand the difference between DATA step compile time and DATA step execution time??? And what happens in each of these phases of a simple program??? Do you understand the difference between an &amp;amp;macvar reference, a call symput as far as the creation of macro variables??? Do you understand what a macro program %macpgm really is and how it ONLY generates code that will get sent forward to the compiler????&lt;BR /&gt;
 &lt;BR /&gt;
  OK, then, once you understand that, you have to understand that the SAS Macro facility has a word scanning and macro trigger resolution phase that happens before ANY code is compiled by the "regular" compiler. By the time the word scanning and macro trigger resolution phase is over there are NO &amp;amp;macvar or %macpgm references in your program. So for just one example,...a %LET out in open code will get executed one time, and only one time -- when code is compiled by the "regular" compiler. A %LET statement inside a macro program will work a bit differently, but essentially, a %LET statement does not "communicate" with an executing DATA step program.&lt;BR /&gt;
&lt;BR /&gt;
 Do NOT try to make a shortcut with macros until you understand, really understand, what your working, non-macroized program, looks like. You can also make sure that your program is error free before you go forward with a macro approach. (Because it is very hard to separate out whether your error messages come from your original program or your generated code.) I think that you really need to take a step back and stop thinking about Macro %DO loops and look at ARRAY processing.&lt;BR /&gt;
 &lt;BR /&gt;
For example, the 2 programs below show the difference with a DATA step DO loop WITHOUT an ARRAY and WITH an ARRAY. No macros involved. Which DATA step program -- just for the calculation of "NEWN" variables-- is closer to what you want/need to do??  (LOG output is shown with the result of the PUTLOG statements.)&lt;BR /&gt;
 &lt;BR /&gt;
This is a good introduction to ARRAY processing.&lt;BR /&gt;
&lt;A href="http://support.sas.com/rnd/papers/sgf07/arrays1780.pdf" target="_blank"&gt;http://support.sas.com/rnd/papers/sgf07/arrays1780.pdf&lt;/A&gt;&lt;BR /&gt;
     &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
NO ARRAYS/NO MACRO&lt;BR /&gt;
5253  data testit;&lt;BR /&gt;
5254    ** make the VARN and NEWN variables without any macros;&lt;BR /&gt;
5255    do i = 0 to 6;&lt;BR /&gt;
5256       putlog '----- INSIDE TOP of LOOP ' _n_= '|' i= '|'  ;&lt;BR /&gt;
5257       x=uniform(-1);&lt;BR /&gt;
5258       varn=i + 10;&lt;BR /&gt;
5259       newn = varn + x;&lt;BR /&gt;
5260       putlog '----- INSIDE BOTTOM of LOOP ' _n_= '|'  i= '|' varn= '|' x= '|' newn= '|';&lt;BR /&gt;
5261       putlog ' ';&lt;BR /&gt;
5262     end;&lt;BR /&gt;
5263&lt;BR /&gt;
5264     putlog '-----what is in TESTIT -- ONLY 1 OBS';&lt;BR /&gt;
5265     putlog '-----OUTSIDE of LOOP ';&lt;BR /&gt;
5266     putlog _all_;&lt;BR /&gt;
5267     putlog '*************************************************';&lt;BR /&gt;
5268  run;&lt;BR /&gt;
                               &lt;BR /&gt;
----- INSIDE TOP of LOOP _N_=1 |i=0 |&lt;BR /&gt;
----- INSIDE BOTTOM of LOOP _N_=1 |i=0 |varn=10 |x=0.0328104845 |newn=10.032810485 |&lt;BR /&gt;
                          &lt;BR /&gt;
----- INSIDE TOP of LOOP _N_=1 |i=1 |&lt;BR /&gt;
----- INSIDE BOTTOM of LOOP _N_=1 |i=1 |varn=11 |x=0.7854493804 |newn=11.78544938 |&lt;BR /&gt;
                    &lt;BR /&gt;
----- INSIDE TOP of LOOP _N_=1 |i=2 |&lt;BR /&gt;
----- INSIDE BOTTOM of LOOP _N_=1 |i=2 |varn=12 |x=0.5329144548 |newn=12.532914455 |&lt;BR /&gt;
                      &lt;BR /&gt;
----- INSIDE TOP of LOOP _N_=1 |i=3 |&lt;BR /&gt;
----- INSIDE BOTTOM of LOOP _N_=1 |i=3 |varn=13 |x=0.2107451191 |newn=13.210745119 |&lt;BR /&gt;
                        &lt;BR /&gt;
----- INSIDE TOP of LOOP _N_=1 |i=4 |&lt;BR /&gt;
----- INSIDE BOTTOM of LOOP _N_=1 |i=4 |varn=14 |x=0.1058570995 |newn=14.105857099 |&lt;BR /&gt;
                 &lt;BR /&gt;
----- INSIDE TOP of LOOP _N_=1 |i=5 |&lt;BR /&gt;
----- INSIDE BOTTOM of LOOP _N_=1 |i=5 |varn=15 |x=0.2827750655 |newn=15.282775066 |&lt;BR /&gt;
                     &lt;BR /&gt;
----- INSIDE TOP of LOOP _N_=1 |i=6 |&lt;BR /&gt;
----- INSIDE BOTTOM of LOOP _N_=1 |i=6 |varn=16 |x=0.7087042163 |newn=16.708704216 |&lt;BR /&gt;
                    &lt;BR /&gt;
-----what is in TESTIT -- ONLY 1 OBS&lt;BR /&gt;
-----OUTSIDE of LOOP&lt;BR /&gt;
i=7 x=0.7087042163 varn=16 newn=16.708704216 _ERROR_=0 _N_=1&lt;BR /&gt;
*************************************************&lt;BR /&gt;
NOTE: The data set WORK.TESTIT has 1 observations and 4 variables.&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.04 seconds&lt;BR /&gt;
      cpu time            0.01 seconds&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                           &lt;BR /&gt;
                 versus&lt;BR /&gt;
   &lt;BR /&gt;
[pre]&lt;BR /&gt;
WITH ARRAY/NO MACRO&lt;BR /&gt;
5270  data testit2;&lt;BR /&gt;
5271    array new{0:6} newn0-newn6;&lt;BR /&gt;
5272    ** use an array;&lt;BR /&gt;
5273    do i = 0 to 6;&lt;BR /&gt;
5274       putlog '----- INSIDE TOP of LOOP ' _n_= '|' i= '|'  ;&lt;BR /&gt;
5275       x=uniform(-1);&lt;BR /&gt;
5276       varn=i + 10;&lt;BR /&gt;
5277       new(i) = varn + x;&lt;BR /&gt;
5278       putlog '----- INSIDE BOTTOM of LOOP ' _n_= '|'  i= '|' varn= '|' x= '|' new(i)= '|';&lt;BR /&gt;
5279       putlog ' ';&lt;BR /&gt;
5280     end;&lt;BR /&gt;
5281&lt;BR /&gt;
5282     putlog '-----what is in TESTIT2 -- ONLY 1 OBS, but now have variables NEWN0-NEWN6';&lt;BR /&gt;
5283     putlog '-----OUTSIDE of LOOP ' ;&lt;BR /&gt;
5284     putlog _all_;&lt;BR /&gt;
5285     putlog '*************************************************';&lt;BR /&gt;
5286  run;&lt;BR /&gt;
                                           &lt;BR /&gt;
----- INSIDE TOP of LOOP _N_=1 |i=0 |&lt;BR /&gt;
----- INSIDE BOTTOM of LOOP _N_=1 |i=0 |varn=10 |x=0.1132566063 |newn0=10.113256606 |&lt;BR /&gt;
                               &lt;BR /&gt;
----- INSIDE TOP of LOOP _N_=1 |i=1 |&lt;BR /&gt;
----- INSIDE BOTTOM of LOOP _N_=1 |i=1 |varn=11 |x=0.7052701673 |newn1=11.705270167 |&lt;BR /&gt;
                                  &lt;BR /&gt;
----- INSIDE TOP of LOOP _N_=1 |i=2 |&lt;BR /&gt;
----- INSIDE BOTTOM of LOOP _N_=1 |i=2 |varn=12 |x=0.8287894241 |newn2=12.828789424 |&lt;BR /&gt;
                               &lt;BR /&gt;
----- INSIDE TOP of LOOP _N_=1 |i=3 |&lt;BR /&gt;
----- INSIDE BOTTOM of LOOP _N_=1 |i=3 |varn=13 |x=0.3050844866 |newn3=13.305084487 |&lt;BR /&gt;
                       &lt;BR /&gt;
----- INSIDE TOP of LOOP _N_=1 |i=4 |&lt;BR /&gt;
----- INSIDE BOTTOM of LOOP _N_=1 |i=4 |varn=14 |x=0.1069306373 |newn4=14.106930637 |&lt;BR /&gt;
                          &lt;BR /&gt;
----- INSIDE TOP of LOOP _N_=1 |i=5 |&lt;BR /&gt;
----- INSIDE BOTTOM of LOOP _N_=1 |i=5 |varn=15 |x=0.9160557245 |newn5=15.916055724 |&lt;BR /&gt;
                            &lt;BR /&gt;
----- INSIDE TOP of LOOP _N_=1 |i=6 |&lt;BR /&gt;
----- INSIDE BOTTOM of LOOP _N_=1 |i=6 |varn=16 |x=0.0842098724 |newn6=16.084209872 |&lt;BR /&gt;
                  &lt;BR /&gt;
-----what is in TESTIT2 -- ONLY 1 OBS, but now have variables NEWN0-NEWN6&lt;BR /&gt;
-----OUTSIDE of LOOP&lt;BR /&gt;
newn0=10.113256606 newn1=11.705270167 newn2=12.828789424 newn3=13.305084487 newn4=14.106930637&lt;BR /&gt;
newn5=15.916055724 newn6=16.084209872 i=7 x=0.0842098724 varn=16 _ERROR_=0 _N_=1&lt;BR /&gt;
*************************************************&lt;BR /&gt;
NOTE: The data set WORK.TESTIT2 has 1 observations and 10 variables.&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.09 seconds&lt;BR /&gt;
      cpu time            0.03 seconds&lt;BR /&gt;
[/pre]</description>
      <pubDate>Fri, 07 Jan 2011 22:32:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Accessing-variable-condition-on-macro-variable-value-in-loop/m-p/60163#M12996</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2011-01-07T22:32:20Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing variable condition on macro variable value in loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Accessing-variable-condition-on-macro-variable-value-in-loop/m-p/60164#M12997</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your reply. The programs you display are somewhat similar to what I need to achieve; I think the one below does the actual calculation I want in the array format that you recommend. &lt;BR /&gt;
&lt;BR /&gt;
Nonetheless, the first issue I really need to resolve before I can continue is how to use the value of a variable (in my case, the value of the variable "flight_counter") to call up another variable to be changed (with the prefix ac_cat_, and a suffix dependent on "flight_counter". So, for example, when flight_counter = 1, I need to insert the value of "n" into the variable "ac_cat_1" ; when flight_counter = 2, insert the value of "n" into "ac_cat_2" ; and so on. The set of variables prefixed "ac_cat_" is created, and filled with ".". I need a statement before the end of the "if" statement to populate the appropriate "ac_cat_" variable with the value of "n". For now, I have inserted the line "ac_cat_1 = n;", but the "1" needs to be changed to a reference to the value of "flight_counter". This is the information that I absolutely need to store from the output of the process below. As I mentioned in an earlier post, I would eventually like to use a "do while" loop, changing "condition" at the end of each turn of the loop, such that the process is repeated until "condition" reaches 0. This will require "flight_counter" to increase an unknown number of times.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data mydata_out; set mydata ;&lt;BR /&gt;
flight_counter = 0;&lt;BR /&gt;
empty_seat_counter = sgmt_empty_seats;	&lt;BR /&gt;
remaining_pass_counter = add_passenger_demand;		&lt;BR /&gt;
condition = remaining_pass_counter &amp;gt;= .25*empty_seat_counter;	&lt;BR /&gt;
&lt;BR /&gt;
if condition = 1 then do; &lt;BR /&gt;
	drop i ;&lt;BR /&gt;
	flight_counter = flight_counter + 1;&lt;BR /&gt;
	array cum_p {0:6}  cum_p_0 - cum_p_6;&lt;BR /&gt;
	array lf {0:6} load_factor_0 - load_factor_6;&lt;BR /&gt;
	array choose{0:6};&lt;BR /&gt;
&lt;BR /&gt;
	do i = 0 to 6 ;&lt;BR /&gt;
		x = uniform(-1)  ;&lt;BR /&gt;
		choose{i} = x &amp;gt;= cum_p{i} ;&lt;BR /&gt;
	end;&lt;BR /&gt;
	n = n = sum(of choose{*}); &lt;BR /&gt;
&lt;BR /&gt;
	load_factor_chosen = lf{n} ;&lt;BR /&gt;
	ac_cat_1 = n;&lt;BR /&gt;
&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;U&gt;&lt;/U&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I realize that I have quite a bit to learn about macros the details of SAS processing, and that seems to have ignited a bit of indignation.....However, I would really appreciate if someone could provide insight into this particular issue (which is probably quite simple), since figuring that out is crucial for me.&lt;B&gt;&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
Thanks very much, &lt;BR /&gt;
R.&lt;BR /&gt;
&lt;BR /&gt;
I am going to repost this message under a new thread, since my current question has little to do with the initial issue.&lt;BR /&gt;
 &lt;BR /&gt;
Message was edited by: rdwest</description>
      <pubDate>Sat, 08 Jan 2011 19:12:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Accessing-variable-condition-on-macro-variable-value-in-loop/m-p/60164#M12997</guid>
      <dc:creator>rdwest</dc:creator>
      <dc:date>2011-01-08T19:12:10Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing variable condition on macro variable value in loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Accessing-variable-condition-on-macro-variable-value-in-loop/m-p/60165#M12998</link>
      <description>Hi:&lt;BR /&gt;
  Sorry -- previous posts were not signs of indignation -- I tried to be emphatic enough to prompt you do some reading and understanding before you went down a road that might, in the end, prove to be fruitless.&lt;BR /&gt;
&lt;BR /&gt;
  The index for an ARRAY reference does NOT need to be I or the variable used to iterate a DO loop. For example, a very handy method for referencing an ARRAY member is to use another variable. For example:&lt;BR /&gt;
[pre]&lt;BR /&gt;
array acc AC_CAT_1-AC_CAT_200;&lt;BR /&gt;
n = some calc;&lt;BR /&gt;
flight_number=1;&lt;BR /&gt;
acc(flight_number) = n;   /* however you calculate N */&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                           &lt;BR /&gt;
In this instance, when the value of FLIGHT_NUMBER is 1, then AC_CAT_1 would get assigned the current value of N, however you calculated it.&lt;BR /&gt;
&lt;BR /&gt;
On pages 7 and 8 of the Array paper I referenced above, is an different example, where the data has a variable called EXPENSE, which is a code that represents an expense type from 1 to 6. And, then in the program, the value of the TYPEOFEXPENSE variable is set using the value of the EXPENSE variable as the index for the NAME array.&lt;BR /&gt;
                                                       &lt;BR /&gt;
The fact is that your FLIGHT_NUMBER could be calculated from some computation in your program or from some variable in your dataset, and as long as the generated value was an integer number, the variable value CAN be used as an array index. That would mean that your numbered AC_CAT_x variables would also have to be declared as an array. It doesn't matter whether you know the number of array elements that you will have in the beginning -- the easiest thing to do is to just make a really big array that will hold all the possible AC_CAT_x variables that your program could create.&lt;BR /&gt;
 &lt;BR /&gt;
Consider the program below. The calculation for FLIGHT_NUMBER is inside a DO LOOP, but the value of FLIGHT_NUMBER is set based on other variables. The AGE and HEIGHT variables are used (in a rather silly way) to create the FLIGHT_NUMBER variable. I just used calculations that would result in a number between 1 and 10. Then, the value for my AC_CAT_x variable is being set, on each iteration through the loop, to some RANUNI value -- but as you can see, for Alfred's observation, the generated FLIGHT_NUMBER values are 1, 4 and 6, while for Barbara's observation (obs #3), the generated FLIGHT_NUMBER values are 1, 3 and 6. For each observation, different AC_CAT_x variables will be "filled" with a random number based on the expression used to calculate FLIGHT_NUMBER. &lt;BR /&gt;
 &lt;BR /&gt;
In addition, the program shows how to sum up numbered variables used in an ARRAY -- by using the SUM function with the OF and a variable list. For my ARRAY, there are some array members that have missing values and that's OK because the SUM function ignores missing values, so my TOTACC variable is the sum of only the array members that have values. The TOTACC2 variable shows an alternate way to sum up the members of an ARRAY.&lt;BR /&gt;
 &lt;BR /&gt;
Useful functions that were designed for ARRAYS are the DIM, HBOUND and LBOUND functions. I haven't used them in my program, but they are mentioned in the doc and in the papers below.&lt;BR /&gt;
 &lt;BR /&gt;
Some other good papers with ARRAY examples:&lt;BR /&gt;
&lt;A href="http://support.sas.com/resources/papers/proceedings09/032-2009.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings09/032-2009.pdf&lt;/A&gt; (more examples of using other variables as an array index)&lt;BR /&gt;
&lt;A href="http://support.sas.com/resources/papers/proceedings09/155-2009.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings09/155-2009.pdf&lt;/A&gt; (how to use arrays in DO loops)&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi29/158-29.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi29/158-29.pdf&lt;/A&gt; (some examples of multi-dimensional arrays and coding techniques)&lt;BR /&gt;
    &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
578  data makedata;&lt;BR /&gt;
579    set sashelp.class(obs=3);&lt;BR /&gt;
580    array acc ac_cat_1-ac_cat_10;&lt;BR /&gt;
581    putlog '**** start DO loop';&lt;BR /&gt;
582    putlog _n_= name= age= height=;&lt;BR /&gt;
583    ** Even though i goes from 1 to 3, FLIGHT_NUMBER is calculated by performing;&lt;BR /&gt;
584    ** some calculation using AGE and HEIGHT -- for the first 3 obs, the numbers generated;&lt;BR /&gt;
585    ** for FLIGHT_NUMBER will fall between 1 and 7 --;&lt;BR /&gt;
586    ** so I made my ARRAY bigger than 7.;&lt;BR /&gt;
587    do i = 1 to 3 by 1;&lt;BR /&gt;
588       if i = 1 then flight_number = round((age/10),1);&lt;BR /&gt;
589       else if i = 2 then flight_number = floor(((age/10)*3));&lt;BR /&gt;
590       else if i = 3 then flight_number = floor((height/10));&lt;BR /&gt;
591&lt;BR /&gt;
592       acc(flight_number) = ranuni(age + i);&lt;BR /&gt;
593       putlog '     ' i= flight_number= acc(flight_number)=;&lt;BR /&gt;
594    end;&lt;BR /&gt;
595    ** Now total up all array members and with SUM function, missing values will be ignored;&lt;BR /&gt;
596    totacc = sum(of ac_cat_1-ac_cat_10);&lt;BR /&gt;
597    totacc2 = sum(of acc(*));&lt;BR /&gt;
598    putlog 'Outside Loop, TOTAL of all array members is): ' totacc=;&lt;BR /&gt;
599    putlog 'Alternate Method of summing array members: ' totacc2;&lt;BR /&gt;
600    putlog '**** output observation';&lt;BR /&gt;
601    putlog ' ';&lt;BR /&gt;
602  run;&lt;BR /&gt;
                      &lt;BR /&gt;
**** start DO loop&lt;BR /&gt;
_N_=1 Name=Alfred Age=14 Height=69&lt;BR /&gt;
     i=1 flight_number=1 ac_cat_1=0.7744385473&lt;BR /&gt;
     i=2 flight_number=4 ac_cat_4=0.5513307348&lt;BR /&gt;
     i=3 flight_number=6 ac_cat_6=0.9973645913&lt;BR /&gt;
Outside Loop, TOTAL of all array members is): totacc=2.3231338734&lt;BR /&gt;
Alternate Method of summing array members: 2.3231338734&lt;BR /&gt;
**** output observation&lt;BR /&gt;
                  &lt;BR /&gt;
**** start DO loop&lt;BR /&gt;
_N_=2 Name=Alice Age=13 Height=56.5&lt;BR /&gt;
     i=1 flight_number=1 ac_cat_1=0.8909796806&lt;BR /&gt;
     i=2 flight_number=3 ac_cat_3=0.824038668&lt;BR /&gt;
     i=3 flight_number=5 ac_cat_5=0.5391602463&lt;BR /&gt;
Outside Loop, TOTAL of all array members is): totacc=2.2541785949&lt;BR /&gt;
Alternate Method of summing array members: 2.2541785949&lt;BR /&gt;
**** output observation&lt;BR /&gt;
                   &lt;BR /&gt;
**** start DO loop&lt;BR /&gt;
_N_=3 Name=Barbara Age=13 Height=65.3&lt;BR /&gt;
     i=1 flight_number=1 ac_cat_1=0.1446875972&lt;BR /&gt;
     i=2 flight_number=3 ac_cat_3=0.9753758423&lt;BR /&gt;
     i=3 flight_number=6 ac_cat_6=0.7469103931&lt;BR /&gt;
Outside Loop, TOTAL of all array members is): totacc=1.8669738327&lt;BR /&gt;
Alternate Method of summing array members: 1.8669738327&lt;BR /&gt;
**** output observation&lt;BR /&gt;
NOTE: There were 3 observations read from the data set SASHELP.CLASS.&lt;BR /&gt;
NOTE: The data set WORK.MAKEDATA has 3 observations and 19 variables.&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.29 seconds&lt;BR /&gt;
      cpu time            0.03 seconds &lt;BR /&gt;
                                      [/pre]</description>
      <pubDate>Sat, 08 Jan 2011 20:57:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Accessing-variable-condition-on-macro-variable-value-in-loop/m-p/60165#M12998</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2011-01-08T20:57:50Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing variable condition on macro variable value in loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Accessing-variable-condition-on-macro-variable-value-in-loop/m-p/60166#M12999</link>
      <description>Thank you, Cynthia - that's exactly what I needed! I think I was confused by the fact that the values of macro variables couldn't be used in the calling up the name of a variable, and I overlooked the fact that array values can be. And, furthermore, I don't think I realized that arrays are created directly as variables in the dataset (I thought they were stored for use in the code, rather than generated as variables). Using arrays makes this much more straightforward. I did as you suggested an used the value of flight_counter (as tracked through the loop by "f") to index the variables AC_CAT_f.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Thank you VERY much for all of your advice -- the array documentation is very helpful.&lt;BR /&gt;
&lt;BR /&gt;
Best,&lt;BR /&gt;
R.&lt;BR /&gt;
&lt;BR /&gt;
data mydata_out; set mydata ;&lt;BR /&gt;
%let y = 5;																		/* Number of times to repeat loop */&lt;BR /&gt;
flight_counter = 0;																	/* Initialize flight counter */&lt;BR /&gt;
	&lt;BR /&gt;
empty_seat_counter = sgmt_empty_seats;												/* Initial variable values */&lt;BR /&gt;
remaining_pass_counter = add_passenger_demand;				&lt;BR /&gt;
condition = remaining_pass_counter &amp;gt;= .25*empty_seat_counter;						/* Condition for additional plane selection */				&lt;BR /&gt;
&lt;BR /&gt;
array ac_cat_{&amp;amp;y}; array lf_chosen_{&amp;amp;y}; array spp_chosen_{&amp;amp;y};						/* Define arrays */&lt;BR /&gt;
array new_dep_perf_{0:6};&lt;BR /&gt;
drop k; do k = 0 to 6;&lt;BR /&gt;
	new_dep_perf_{k} = 0;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
drop f;&lt;BR /&gt;
do f = 1 to &amp;amp;y;&lt;BR /&gt;
	if condition = 1 then do; &lt;BR /&gt;
		&lt;BR /&gt;
		flight_counter = flight_counter + 1;&lt;BR /&gt;
&lt;BR /&gt;
		array cum_p {0:6}  cum_p_0 - cum_p_6;&lt;BR /&gt;
		array lf {0:6} load_factor_0 - load_factor_6;		&lt;BR /&gt;
		array spp {0:6} seats_per_plane_0 - seats_per_plane_6;&lt;BR /&gt;
&lt;BR /&gt;
		array choose{0:6};																		/* Empty array for AC choices */&lt;BR /&gt;
&lt;BR /&gt;
		drop i ;&lt;BR /&gt;
		do i = 0 to 6 ;&lt;BR /&gt;
			x = uniform(-1)  ;																	/* Random number draw */&lt;BR /&gt;
			choose{i} = x &amp;gt;= cum_p{i} ;&lt;BR /&gt;
		end;&lt;BR /&gt;
		n = sum(of choose{*}); 																	/* Calculate chosen AC category */&lt;BR /&gt;
&lt;BR /&gt;
		ac_cat_{f} = n;																			/* Record chosen AC category */&lt;BR /&gt;
		lf_chosen_{f} = lf{n} ;																	/* Record corresponding load factor */&lt;BR /&gt;
		spp_chosen_{f} = spp{n};																/* Record corresponding seats per plane */			&lt;BR /&gt;
		&lt;BR /&gt;
		remaining_pass_counter = remaining_pass_counter - (lf{n} * spp{n});						/* Recalculate remaining passengers */&lt;BR /&gt;
		empty_seat_counter = sgmt_empty_seats + (1 - (lf{n} * spp{n}));							/* Recalculate empty seats */&lt;BR /&gt;
		condition = remaining_pass_counter &amp;gt;= .25*empty_seat_counter;							/* Recalculate condition for loop */&lt;BR /&gt;
&lt;BR /&gt;
		new_dep_perf_{n} = new_dep_perf_{n} + 1; &lt;BR /&gt;
	end;&lt;BR /&gt;
	&lt;BR /&gt;
end;&lt;BR /&gt;
	&lt;BR /&gt;
run;</description>
      <pubDate>Sat, 08 Jan 2011 21:58:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Accessing-variable-condition-on-macro-variable-value-in-loop/m-p/60166#M12999</guid>
      <dc:creator>rdwest</dc:creator>
      <dc:date>2011-01-08T21:58:54Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing variable condition on macro variable value in loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Accessing-variable-condition-on-macro-variable-value-in-loop/m-p/60167#M13000</link>
      <description>Hi:&lt;BR /&gt;
  Yes, that's almost exactly right. Most folks who have ordered or numbered variables, such as VAR1-VAR10 -- think of them almost intuitively as belonging in an array structure.&lt;BR /&gt;
 &lt;BR /&gt;
  For SAS datasets, the numbered variable names are what is permanently stored  in the physical data. While a DATA step program is active, however, you can build an ARRAY reference, such as:&lt;BR /&gt;
[pre]&lt;BR /&gt;
array myvar var1-var10;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                    &lt;BR /&gt;
and then you can refer --in the program and &lt;U&gt;ONLY&lt;/U&gt; in the program to&lt;BR /&gt;
[pre]&lt;BR /&gt;
myvar(1) or myvar(i) or myvar(flight_number)&lt;BR /&gt;
[/pre] &lt;BR /&gt;
                               &lt;BR /&gt;
Once the variables are stored back in the physical storage location again, if you do a PROC CONTENTS, you will see only VAR1-VAR10 -- you will never see a reference to the "myvar" array. Some data base and other file format structures do store the array name physically as a data structure. However, SAS does not.&lt;BR /&gt;
              &lt;BR /&gt;
In fact, in one program, you could have&lt;BR /&gt;
[pre]&lt;BR /&gt;
array myvar var1-var10&lt;BR /&gt;
        &lt;BR /&gt;
and in a different program have the reference&lt;BR /&gt;
  &lt;BR /&gt;
array xyz var1-var10;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
   &lt;BR /&gt;
and, even though "numbered" variables are the most frequent reason for using ARRAYS and DO loops in a DATA step program, you can also declare a group of "unnumbered" variables to be in an ARRAY for purposes of processing. For example:&lt;BR /&gt;
[pre]&lt;BR /&gt;
array nvar (*) _numeric_;  (all numeric variables in an array)&lt;BR /&gt;
array cvar (*) _character_; (all character variables in an array)&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
Note how, in the program below, you do not see any "numbered" variables from the result of the PUTLOG. Even though I referenced cvar(i) and nvar(i) in the DO loop, the log shows you the actual names of the variables, not the "array" reference:&lt;BR /&gt;
[pre]&lt;BR /&gt;
650  data tryarr;&lt;BR /&gt;
651    set sashelp.class(obs=2);&lt;BR /&gt;
652    array cvar (*) _character_;&lt;BR /&gt;
653    array nvar (*) _numeric_;&lt;BR /&gt;
654    putlog 'CVAR Array Ref';&lt;BR /&gt;
655    do i = 1 to dim(cvar);&lt;BR /&gt;
656       putlog i= cvar(i)=;&lt;BR /&gt;
657    end;&lt;BR /&gt;
658&lt;BR /&gt;
659    putlog 'NVAR Array Ref';&lt;BR /&gt;
660    do i = 1 to dim(nvar);&lt;BR /&gt;
661       putlog i= nvar(i)=;&lt;BR /&gt;
662    end;&lt;BR /&gt;
663&lt;BR /&gt;
664  run;&lt;BR /&gt;
                    &lt;BR /&gt;
CVAR Array Ref&lt;BR /&gt;
i=1 Name=Alfred&lt;BR /&gt;
i=2 Sex=M&lt;BR /&gt;
NVAR Array Ref&lt;BR /&gt;
i=1 Age=14&lt;BR /&gt;
i=2 Height=69&lt;BR /&gt;
i=3 Weight=112.5&lt;BR /&gt;
CVAR Array Ref&lt;BR /&gt;
i=1 Name=Alice&lt;BR /&gt;
i=2 Sex=F&lt;BR /&gt;
NVAR Array Ref&lt;BR /&gt;
i=1 Age=13&lt;BR /&gt;
i=2 Height=56.5&lt;BR /&gt;
i=3 Weight=84&lt;BR /&gt;
NOTE: There were 2 observations read from the data set SASHELP.CLASS.&lt;BR /&gt;
NOTE: The data set WORK.TRYARR has 2 observations and 6 variables.&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.03 seconds&lt;BR /&gt;
      cpu time            0.03 seconds&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                &lt;BR /&gt;
So, there are a lot of neat things that you can do with arrays -- no macros needed. If you do a Google search or a search for user-group and SAS Global Forum papers, you will find a lot more papers that explain the ins and outs of ARRAY processing.  There is a place for using macro %DO loops, but it didn't seem that you were at that place.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Sat, 08 Jan 2011 23:51:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Accessing-variable-condition-on-macro-variable-value-in-loop/m-p/60167#M13000</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2011-01-08T23:51:36Z</dc:date>
    </item>
  </channel>
</rss>

