Go Back   Rhinocerus > Newsgroup > Newsgroup comp.soft-sys.sas

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 11-10-2004, 04:12 PM
Sigurd Hermansen
Guest
 
Posts: n/a
Default Re: What's wrong with this macro? Thank you

Hamani:
The SAS Macro %if processing occurs before the CALL SYMPUT reads the column
variable col1 during the execution of the Data step. A SAS Macro condition
or loop constructs Data step statements or PROC's for subsequent execution.
Although devices such as SYSFUNC() cross-over the boundary between SAS Macro
statement and Data step statement processing, Data step statements within
Macro conditions or loops do not as a rule execute until after the Macro
evaluates conditions and places Data step statements on the program vector.
Sig

-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
Elmaache, Hamani
Sent: Wednesday, November 10, 2004 11:22 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: What's wrong with this macro? Thank you


Thank you evryone for your help.

%macro TC_METHOD( TC_CENTER=, METHOD=);
%global value;
option mprint;
data _NULL_;
set test2;
if TC=&TC_CENTER and _name_=&METHOD then do;
call symput('value',left(put(col1,10.0)));
stop;
end;
RUN;
%mend TC_METHOD;

With a nice help from Zack, Matthew M. ,I fixed my problem.
But I still wondring why this macro does't when I use the percent symbol:

%if TC=&TC_CENTER and _name_=&METHOD %then %do;
call symput('value',left(put(col1,10.0)));
stop;
%end;
..

Sure, because, I illegally mixe up SAS and
macro code.
My problem has been fixed, I just want to understand.
Thanks again.
Hamani.




-----Original Message-----
From: Ed Heaton [mailto:EdHeaton@WESTAT.COM]
Sent: November 9, 2004 8:02 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: What's wrong with this macro?


Yes, Jim, you can get the VALUE from a macro variable that was specified
with SYMPUT in the same DATA step. I emphasize the word VALUE. That's not
the same as being able to use the macro variable in the DATA step. The
SYMGET function returns a DATA step value, a macro variable returns SAS
code.

Consider the following log.
================================================== ======================
1 Data _null_ ;
2 Call symPut( 'value' , "col1" ) ;
3 %put '///////////////////' ;
'///////////////////'
4 %put &value ;
WARNING: Apparent symbolic reference VALUE not resolved.
&value
5 %put '///////////////////' ;
'///////////////////'
6 Run ;
================================================== ======================

The %PUT statements execute at compile time. Look at this log.
================================================== ======================
7 Data test ;
8 Do i=1 to 5 ; Drop i ;
9 id = put( i , 1. ) ;
10 Output ;
11 End ;
12 Run ;

NOTE: The data set WORK.TEST has 5 observations and 1 variables.
NOTE: DATA statement used:
real time 0.01 seconds
cpu time 0.01 seconds

13 Data _null_ ;
14 Set test ;
15 If ( _n_ eq 1 ) then call symPut( "mId" , id ) ;
16 %put &mId ;
WARNING: Apparent symbolic reference MID not resolved.
&mId
17 Run ;
================================================== ======================

Notice that the DATA set looped five times, but &mId only printed once. And
it printed before the RUN statement. That's because the %PUT statement
executed at compile time. But the SYMPUT function processed it's arguments
at run time. So, there is no way the %PUT statement could have known the
value that would be put in the macro variable.

Ed

Edward Heaton, SAS Senior Systems Analyst,
Westat (An Employee-Owned Research Corporation),
1600 Research Boulevard, RW-3541, Rockville, MD 20850-3195
Voice: (301) 610-4818 Fax: (301) 610-5128
mailto:EdHeaton@Westat.com http://www.Westat.com

-----Original Message-----
From: Jim Groeneveld [mailto:jim1stat@YAHOO.CO.UK]
Sent: Tuesday, November 09, 2004 4:17 AM
To: SAS-L@LISTSERV.UGA.EDU; Ed Heaton
Subject: Re: What's wrong with this macro?


Hi Ed,

I think you actually _can_ obtain the values of macro variables created
during the same data step with CALL SYMPUT with the SYMGET function.
Sometimes that may be a useful feature (I use it sometimes), but in the
present case it would be possible to reach the desired goal without a macro
variable at all (just: PUT Col1=. It seems Hamani illegally mixes SAS and
macro code.

Regards - Jim.
--
Y. (Jim) Groeneveld, MSc., Biostatistician, Science Team Vitatron B.V.,
Meander 1051, 6825 MJ Arnhem P.O.Box 5227, 6802 EE Arnhem, the Netherlands
Tel: +31/0 26 376 7365, Fax: +31/0 26 376 7305
Jim.Groeneveld_AT_Vitatron.com (replace _AT_ by AT sign)
http://www.vitatron.com, http://home.hccnet.nl/jim.groeneveld

My computer multi-boots OS's, each of them adapting the DST twice a year.

[common disclaimer]

On Mon, 8 Nov 2004 16:52:00 -0500, Ed Heaton <EdHeaton@WESTAT.COM> wrote:

>Hamani,
>
>Macro variables created with CALL SYMPUT are not available until after
>the DATA step ends. You are trying to access it within the DATA step.
>
>Ed
>
>Edward Heaton, SAS Senior Systems Analyst,
>Westat (An Employee-Owned Research Corporation),
>1600 Research Boulevard, RW-3541, Rockville, MD 20850-3195
>Voice: (301) 610-4818 Fax: (301) 610-5128
>mailto:EdHeaton@Westat.com http://www.Westat.com
>
>
>-----Original Message-----
>From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
>Elmaache, Hamani
>Sent: Monday, November 08, 2004 4:24 PM
>To: SAS-L@LISTSERV.UGA.EDU
>Subject: What's wrong with this macro?
>
>
>I wrote this small macro, and I got all time this mesage:
>
>'///////////////////'
>WARNING: Apparent symbolic reference VALUE not resolved.
>'///////////////////' &value '///////////////////'
> Can somebady help.
>Thanks a lot.
>
>/******************************/
>
> %macro TC_TYDES( TC_name=, TYPES=);
> data _NULL_;
> set test2;
> %if TC=&TC_name and _name_=&TYPES %then %do;
> call symput('value',col1);%end;
>
> %put '///////////////////';
> %put '///////////////////' &value;
> %put '///////////////////';
> run;
> %mend TC_TYDES;
>
>%TC_TYDES( TC_name='CAN', TYPES='EOL');
>
>/******************************/

Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Macro Quoting Question Kevin Morgan Newsgroup comp.soft-sys.sas 1 07-06-2007 02:47 AM
SCL Joe (was RE: macro structure) Gregg P. Snell Newsgroup comp.soft-sys.sas 0 06-27-2006 07:59 PM
Re: Understanding How Macro Processor Works Terjeson, Mark Newsgroup comp.soft-sys.sas 0 03-24-2006 11:00 PM
Re: MAcro Design was (Re: Macro quoting essentials) Ian Whitlock Newsgroup comp.soft-sys.sas 3 12-11-2005 11:18 PM
Re: What's wrong with this macro? Thank you Ian Whitlock Newsgroup comp.soft-sys.sas 0 11-11-2004 08:29 PM



All times are GMT. The time now is 12:36 PM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.