Date: Wed, 24 May 2006 19:04:08 +0000
Reply-To: toby dunn <tobydunn@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: toby dunn <tobydunn@HOTMAIL.COM>
Subject: Re: Using data step variables in a macro
In-Reply-To: <445d9dbe0605241201y4a4e9b7wad2d3ffb52ebd0c7@mail.gmail.com>
Content-Type: text/plain; format=flowed
As Yu so kindly pointed out I missed deleteing a couple of % signs.
if ( _type_= 'COV' ) %then %do ;
Should have been
if ( _type_= 'COV' ) then do ;
Thank you Yu.
Toby Dunn
From: "Yu Zhang" <zhangyu05@gmail.com>
To: "toby dunn" <tobydunn@hotmail.com>
Subject: Re: Using data step variables in a macro
Date: Wed, 24 May 2006 14:01:47 -0500
Dear Toby,
I think
if ( _type_= 'COV' ) %then %do ; should change to
if ( _type_= 'COV' ) then do . right?
Yu
On 5/24/06, toby dunn <tobydunn@hotmail.com> wrote:
>
>Greg you are mixing data step code with macro.
>
>%macro cm(dsn= , X= , Y= , byvar= ) ;
>
>proc sort
>data = &dsn ;
>by &byvar ;
>run ;
>
>
>proc corr
>data = &dsn cov
>out = outp1 cov noprint ;
>var &X &Y ;
>by &byvar ;
>run ;
>
>
>data _null_ ;
>set outp1 ;
>call symput( 'XX' , left( trim( _name_ ) ) ) ;
>run ;
>
>data outp2( keep = Var1 Var2 Cov &byvar) ;
>retain Var1 Var2 Cov ;
>set outp1 ;
>
>if ( _type_= 'COV' ) %then %do ;
> if ( "&XX" = "&X" ) then do ;
> Var1= "&X" ;
> Cov = "&Y" ;
> end ;
> if ( _name_= "&Y" ) then do ;
> Var2 = "&Y" ;
> end ;
>end ;
>
>run ;
>
>data outp2 ;
>set outp2 ;
>by &byvar ;
>if last.&byvar ;
>run ;
>
>title 'outp2' ;
>
>proc print
>data = outp2 noobs ;
>by &byvar ;
>run ;
>
>Title ;
>
>%mend;
>
>
>
>
>Toby Dunn
>
>
>
>
>
>From: Greg Petroski <petroskig@HEALTH.MISSOURI.EDU>
>Reply-To: Greg Petroski <petroskig@HEALTH.MISSOURI.EDU>
>To: SAS-L@LISTSERV.UGA.EDU
>Subject: Using data step variables in a macro
>Date: Wed, 24 May 2006 14:28:46 -0400
>
>I want to compare values of the macro arguments to values of the _name_
>variable in a data step. This is illustrated in the following code. The
>macro variables are correctly resolved but the comparisons fail. Any
>suggestions will be appreciated.
>
>Greg
>
>%macro cm(dsn, X, Y, byvar);
>proc sort data=&dsn; by &byvar;
>proc corr data=&dsn cov out=outp1 cov noprint;
>var &X &Y ; by &byvar;
>
>data _null_; set outp1; call symput('XX', left(trim(_name_)));
> %put XX --> &XX;
>
>data outp2(keep= Var1 Var2 Cov &byvar);
> retain Var1 Var2 Cov;
>set outp1;
>
>%if _type_= 'COV' %then %do;
> %if &XX = &X %then %do; Var1= &X; Cov= &Y; %end;
> %if _name_= &Y %then %do; Var2= &Y; %end;
>%end;
>
> data outp2; set outp2; by &byvar; if last.&byvar;
>proc print data=outp2 noobs; title 'outp2'; by &byvar;
>%mend;
>
|