Date: Sat, 25 Oct 2008 17:40:29 -0400
Reply-To: Jim Groeneveld <jim.1stat@YAHOO.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jim Groeneveld <jim.1stat@YAHOO.COM>
Subject: Re: Array Frustration!!!!
Hi Lewis,
I looks rather cumbersome and superfluous as your array Knots creates 5
normal variables called Knots1 to Knots5. Those are available in your
dataset One and you can use them from there on. Do a:
PROC PRINT DATA=One; RUN;
But in trying to get your code working you need to know that the global
macro variables FyKnot1 to FyKnot5 can not be referenced as array elements.
Those are fixed names that you can only reference by way of macro code. You
would need a macro loop to reference them. A macro loop is not allowed in
open code, only inside a macro. Thus, while adapting you code minimally it
should become:
%MACRO Looping;
data two;
* set one; * No, you pass those values via macro variables! ;
array x{5};
%do i=1 %to 5; * I is a macro variable too, not a dataset variable;
x{&i}=&&fyknot&i; /* these are values, see your macro docs */
%end;
* output; * redundant as it default outputs the single record;
run; * QUIT is not applicable here;
%MEND Looping;
%Looping
PROC PRINT DATA=Two; RUN;
But if you would transfer more variables and records this way it gets very
cumbersome and complicated. It should not be done that way, except specific
exceptions. What is you larger goal? What do you try to do? There may be a
much better and simple solution for your overall problem.
Regards - Jim.
--
Jim Groeneveld, Netherlands
Statistician, SAS consultant
home.hccnet.nl/jim.groeneveld
On Sat, 25 Oct 2008 14:31:10 -0400, Lewis Jordan <lewjord@UGA.EDU> wrote:
>I am trying to pass an array of variables into another array. In the "data
two" step, if I specify x{1}=&fyknot1, it works fine. However, this is
inefficient and I don't want to have to write out each variable. What am I
doing wrong in the "data two" do loop?
>
>Thanks in advance. -Lewis
>
>data one;
>array knots{5};
> do i=1 to 5;
> knots{i}=ranuni(38211);
> call symput (compress('fyknot'||i),trim(left(knots{i})));
> end;
>drop i;
>run;
>
>data two;set one;
>array x{5};
> do i=1 to 5;
> x{i}=&fyknot{i}; /*HELP ME HERE?????*/
> end;
>output;
>run;quit;