Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating an array

Status
Not open for further replies.

riskassure

Programmer
May 6, 2005
33
US
I have a large table containing hundreds of data fields. There are two sets of fields I'd like to use in particular: Code1 through Code20, as well as Code1Dt through Code20Dt

So in my data step, I have the following:

array Code{*} Code1-Code20

which works fine.

However, when it comes to create an array for Code1Dt through Code20Dt by

array CodeDt{*} Code1Dt-Code20Dt

I get an error. I know it has something to do with the suffix not being numeric. Is there a way to make this work?

Thanks!

~~CW~~
 
No, in order to make use of the shortcut range your variables must end in a number.

You could use a macro to 'write' out the variables into a macro variable and then use that macro var to initialize your array.

Here is an example:

Code:
%macro ExpandAlphaVars(minvarname = true1dt,
                       maxvarname = true22dt);

   %let myvarlist = ;
   %let minvarnum = %sysfunc(compress(&minvarname,1234567890,k));
   %let maxvarnum = %sysfunc(compress(&maxvarname,1234567890,k));
   %let myprefix  = %scan(&minvarname,1,&minvarnum);
   %let mypostfix = %scan(&minvarname,2,&minvarnum);
   %do i=&minvarnum %to &maxvarnum;
     %let myvarlist = &myvarlist &myprefix.&i.&mypostfix;
   %end;
   %put &myvarlist;
%mend ExpandAlphaVars;

Then in your code you can insert the macro name and its parameters, like this...

Code:
*** FROM YOUR CODE ***;
array CodeDt{*} %ExpandAlphaVars(minvarname=Code1Dt,mAXvarname=Code20Dt);

*** CONTINUE WITH YOUR PROGRAM ***;

I hope this helps...
Klaz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top