Date: Fri, 25 Apr 2003 09:08:51 +0100
Reply-To: "ian(freeserve)" <ian@AZORUBINE.FREESERVE.CO.UK>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "ian(freeserve)" <ian@AZORUBINE.FREESERVE.CO.UK>
Subject: Re: IML & macros: Put matrix values into macro variable
Content-Type: text/plain; charset="iso-8859-1"
John,
But what was wrong with the suggestion to keep the text
processing within IML and make use of the rowcat
function? Or am I missing something?
The code below reduces to:
9 proc iml;
NOTE: IML Ready
10 x = {3.1 2.9 1.9,
11 4.0 5.0 6.0,
12 9.65 7.894 8.1,
13 -11.2 -10.9 136.654};
14 call symput("Vector", left(compbl(rowcat(rowcat(char(x))`))));
15 quit;
NOTE: Exiting IML.
NOTE: PROCEDURE IML used:
real time 0.00 seconds
16 %put >>>>>>>>> Vector=&Vector <<<<<<<<<<;
>>>>>>>>> Vector=3.1 2.9 1.9 4 5 6 9.65 7.894 8.1 -11.2 -10.9 136.654
<<<<<<<<<<
Ian
Ian Wakeling
Qi Statistics.
>Date: Thu, 24 Apr 2003 10:58:54 -0400
>From: john.hixon@KODAK.COM
>Subject: IML & macros: Put matrix values into macro variable
>
>/*
>--- Paul Thompson <paul@WUBIOS.WUSTL.EDU> wrote:
>> How can the values of a matrix in SAS/IML be put into a SAS macro
>> variable?
>>
>> You may assume that the macro is a row vector.
>
>You have already recvd a good answer from Dale (as usual).
>Here is another approach. This assumes that you know the number
>of elements that will be in your IML Matrix.
>*/
>
>%let NElements=12;
>
>proc iml;
> x = {3.1 2.9 1.9,
> 4.0 5.0 6.0,
> 9.65 7.894 8.1,
> -11.2 -10.9 136.654};
> rows=nrow(x);
> cols=ncol(x);
> x2=shape(x,1,rows*cols);
> MatColNames=("Matrix1":"Matrix&NElements");
> ColNames1={"RowDimension" "ColumnDimension"};
> ColNames=ColNames1||MatColNames;
> MatrixOut=rows||cols||x2;
> create MatrixOut from MatrixOut [colname=ColNames];
> append from MatrixOut;
>quit;
>
>* Look at output;
>proc print data=MatrixOut;
>run;
>
>* Now define the macro variable as desired:;
>data _null_;
> length LongString$ 300;
> array Matrix(&NElements);
> set MatrixOut;
> do i=1 to &NElements;
> if i= 1 then LongString=left(put(Matrix(i),best.));
> else LongString=trim(LongString)||" "
>||left(put(Matrix(i),best.));
> end;
> call symput('Vector',substr(LongString,1,length(LongString)));
>run;
>
>%put >>>>>>>>> Vector=&Vector <<<<<<<<<<;
>
>*The put statement shows this:
>
>>>>>>>>>> Vector=3.1 2.9 1.9 4 5 6 9.65 7.894 8.1 -11.2 -10.9 136.654
><<<<<<<<<<
>
>HTH?
>
>Best Regards,
>
>John Hixon
>Eastman Kodak Company
>Rochester, NY USA
>585-477-1984
>
>(Embedded image moved to file: pic15281.pcx)
|