Date: Thu, 24 Apr 2003 09:15:47 +0100 "ian(freeserve)" "SAS(r) Discussion" "ian(freeserve)" Re: IML & macros: Put matrix values into macro variable text/plain; charset="iso-8859-1"

Paul and Dale,

I think the trick is to reduce the character matrix representing the row vector to a single element before the call to symput. This can be done using the rowcat() function. Also I guess you may be dealing with different magnitudes of numbers and decimals, so below I export the data with 2 decimal places and use a generous field width to always leave at least one blank between every element in the row-vector and then remove the multiple spaces with compbl().

proc iml; x = {1 2 3 40 500.67}; x_char = char(x,10,2); call symput("vector1", left(compbl(rowcat(x_char)))); quit;

%put vector1=&vector1;

Ian

Ian Wakeling Qi Statistics.

>Date: Wed, 23 Apr 2003 15:50:19 -0700 >From: Dale McLerran <stringplayer_2@YAHOO.COM> >Subject: Re: IML & macros: Put matrix values into macro variable > >Paul, > >CALL SYMPUT can be used in IML. Truth be known, CALL SYMPUT >requires that both arguments be character valued. When CALL >SYMPUT is employed in a datastep and the second argument is >numeric, an implicit conversion from numeric to character is >performed. Such is not the case when CALL SYMPUT is executed >in IML. Both arguments MUST be character for CALL SYMPUT to >execute properly in IML. Also of note is that if you try >to place an entire row vector into a single macro variable, >only the last column of the vector is written to the macro >variable. You must write out the vector elements to separate >macro variables. Here is code which demonstrates: > >proc iml; > x = {1 2 3}; > x_char = char(x); > call symput("vector1", left(x_char)); > call symput("x1", left(char(x[,1]))); > call symput("x2", left(char(x[,2]))); > call symput("x3", left(char(x[,3]))); >quit; > >%put vector1=&vector1; >%put x1=&x1; >%put x2=&x2; >%put x3=&x3; > > >Dale > > >--- 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. > > >===== >--------------------------------------- >Dale McLerran >Fred Hutchinson Cancer Research Center >mailto: dmclerra@fhcrc.org >Ph: (206) 667-2926 >Fax: (206) 667-5977 >---------------------------------------

Back to: Top of message | Previous page | Main SAS-L page