Date: Thu, 7 Feb 2008 15:34:32 -0700
Reply-To: Roberto Valdivia <valdivia@MONTANA.EDU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Roberto Valdivia <valdivia@MONTANA.EDU>
Subject: Re: Help with code in macro
In-Reply-To: <020220080139.13188.47A3C9D10004540A00003384220588644205029A06CE9907@comcast.net>
Content-Type: text/plain; charset="us-ascii"
Hi Ian,
Thanks for the help and the link, both of them helped me to make this work.
I still need to add more things to the program (e.g. some loops to do the
same thing for more sets of equations, etc) but I will try to do it myself
first and If I have more questions I will come back.
Thanks again,
Roberto
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Ian
Whitlock
Sent: Friday, February 01, 2008 6:39 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: FW: Re: Help with code in macro
> Summary: Needs list processing.
> #iw-value=1
>
> Roberto,
>
> Since you didn't explain any of the details of your manipulation, I
> cannot help with them, but from the PROC MEANS step it is clear that
> you want to learn how to manipulate lists.
>
> If you were willing to have standardized names then the MEANS step
> just amounts to using the AUTONAME option. If you really need your
> form of names then I would consider.
>
> %macro mknames ( list = a b c , suff = _S_ ) ;
> %* returns list with suffix added to each element *;
> %* note version 9+ required as written *;
> %local i ;
> %do i = 1 %to &sysmaxlong ;
> %if %length(%scan(&list,&i)) = 0 %then %return ;
> %scan(&list,&i)&suff
> %end ;
> %mend mknames ;
>
> Now the means part of your macro TEST could be.
>
> %macro test(lhs = a b c , rhs = x y ) ;
> ...
> proc means data = <yourdata> ;
> var = &lhs &rhs ;
> by tno ;
> output out = summary
> means=%mknames(list=&lhs, suff=_M_)
> means=%mknames(list=&rhs, suff=_M_)
> sum=%mknames(list=&lhs, suff=_S_)
> sum=%mknames(list=&rhs, suff=_S_)
> ;
> run ;
> ...
> %mend test ;
>
> For more details on handling lists see
> www2.sas.com/proceedings/forum2007/052-2007.pdf
>
> In that paper an off the shelf macro XPROD could produce
> the same thing as the mknames.
>
> means = %xprod(l1=&lhs &rhs, l2=_M_)
> sum = %xprod(l1=&lhs &rhs, l2=_S_)
>
> You also might find %ZIP handy for interleaving the LHS and RHS lists
> if they always have the same length and you want corresponding pairs
> to be consecutive.
>
> Ian Whitlock
|