[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sas-l
Subject:    A perfect solution for : How to provent re-entry when a SAS file
From:       Yu Guo <Yu.Guo () VERISPAN ! COM>
Date:       2002-12-31 22:02:10
[Download RAW message or body]

        After reading the Tips on Writing SAS Macros article written by
Roland, here is my final solution to the INCLUDE problem. It uses the
%GLOBAL declaration trick. It will not generate any warning messages as it
would do in my last samle code.

        Happy new year!

        Raymond


        *-- PURPOSE: prevent running certain code for second time;
        %macro HandleRe_entry_I_HELPFUNC;
                %GLOBAL _INCLUDE_I_HELPFUNC_SAS_;

                %IF %length(&_INCLUDE_I_HELPFUNC_SAS_)  %THEN
                        %put -------- re-entered I_HELPFUNC.SAS;
                %ELSE   %DO;
                        %LET _INCLUDE_I_HELPFUNC_SAS_ = %STR(included);
*-- set entry flag;
                        %put --------- enter I_HELPFUNC.SAS for the first
time;

                        %*-- TODO : put any code you want to run only one
time here;

                %END;
        %mend HandleRe_entry_I_HELPFUNC;


        %HandleRe_entry_I_HELPFUNC;






        From:   Yu Guo/SPEN/ScottLevin@Informatics on 12/23/2002 10:37 AM
        Please respond to CN=Yu Guo/OU=SPEN/O=ScottLevin@Informatics
        To:     SAS-L@LISTSERV.UGA.EDU@SMTP@ExchangePA
        cc:

        Subject:        How to provent re-entry when a SAS file will be
included for mult iple times ???

        Hello everybody,

        I am used to program in C/C++ ways. I am trying to find a way in SAS
program
        to simulate the
        #IF not defined ...
                [code would like to be included only in first time
including]
        #ENDIF.

        In the end is my solution. Does anybody know a better way to do it?
Thanks a
        lot!

        Merry Christmas :)

        -Raymond


        *---------code in a include file, such as
I_HELPFUNC.sas-------------
        *-- PURPOSE: prevent certain code from re-entry ;
        *-- TODO: any better way in SAS to detect if a macro variable could
be
        resolved or not (not in data step)?;
        %macro HandleRe_entry_I_HELPFUNC(includefile);

                %IF "&includefile"  = "1"  %THEN
                        %put -------- re-entered I_HELPFUNC.SAS;
                %ELSE   %DO;
                        %put --------- enter I_HELPFUNC.SAS for the first
time;
                        *TODO : put any code preferring non-re-entry here;
                %END;
        %mend HandleRe_entry_I_HELPFUNC;


        %HandleRe_entry_I_HELPFUNC(&_INCLUDE_I_HELPFUNC_SAS_);

        %LET _INCLUDE_I_HELPFUNC_SAS_ = 1;              *-- set entry flat;

        *other code here;
        *--------------------end of include
file------------------------------;

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic