Date: Wed, 16 Nov 2005 13:13:12 -0500
Reply-To: Ed Heaton <EdHeaton@WESTAT.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Ed Heaton <EdHeaton@WESTAT.COM>
Subject: Re: QUERY: Construction of variable-dimension arrays using macro
variables
Content-Type: text/plain; charset="us-ascii"
Stephen,
You have substantial problems if you want to generate this code on a
single pass through the DATA step. The problem is that the ARRAY
statement is a compile-time statement and the assignment statement is a
run-time statement. DATA steps are compiled before they are run.
You attempted to pass your data through a %LET statement. However, %LET
statements are global and hence executed immediately after they are read
(i.e., before compilation). So, once again, your run-time data is not
available.
A two-step process might be in order. Only you and your task know for
sure.
Data _null_ ;
Len=5 ;
Call symPut( "varLen" , compress( put( len , best. ) ) ) ;
Run ;
Data try ;
Array element[*] a1-a&varlen ;
Run;
Ed
Edward Heaton, SAS Senior Systems Analyst,
Westat (An Employee-Owned Research Corporation),
1600 Research Boulevard, RW-4541, Rockville, MD 20850-3195
Voice: (301) 610-4818 Fax: (301) 294-3879
mailto:EdHeaton@Westat.com http://www.Westat.com
-----Original Message-----
From: owner-sas-l@listserv.uga.edu [mailto:owner-sas-l@listserv.uga.edu]
On Behalf Of Stephan Rudolfer
Sent: Wednesday, November 16, 2005 10:58 AM
To: SAS(r) Discussion
Cc: Stephan Rudolfer
Subject: QUERY: Construction of variable-dimension arrays using macro
variables
Let len denote a positive integer. I wish to create an array of
dimension len. There is a problem here: to create an array, we have to
specify the first and last elements in the array. However, here the
number is a variable, and SAS doesn't seem able to accept an array
element of the form a&len. Naively, I've tried the following code:
Data try;
Len=5;
%let varlen=len;
Array element(len) a1-a&varlen;
Run;
This generates the following log file:
153 data try;
154 len=5;
155 %let varlen=len;
156 %let last=lot&varlen;
SYMBOLGEN: Macro variable VARLEN resolves to len
157 array element(len)
157! a1-a&varlen;
SYMBOLGEN: Macro variable VARLEN resolves to len
ERROR: Missing numeric suffix on a numbered variable list (a1-alen).
WARNING: Defining an array with zero elements.
158 run;
What I was hoping was that the macro substitution would generate
a-len=a5.
Any suggestions would be most gratefully received.