f



Re: Reusing code from SAS Program in another SAS Program #4

In response to a question by Keith, Paul Choate suggested using
%INC. The suggestion is reasonable, but not his explanation.

   Since %INC is a macro you can put it anywhere in open code and
   it will read the code snippet during compilation.

%INC is neither a macro nor a macro instruction.  It is one of a
few old SAS commands that begin with a %-sign and predate the
current macro language.  This can be shown by a batch job run
with the option NOMACRO.  Here is the log.

   NOTE: SAS (r) Proprietary Software Release 8.2 (TS2M0)
         Licensed to The SAS Learning Edition V2.0, Site
         0000514771.
   NOTE: This session is executing on the WIN_PRO  platform.

   NOTE: This version of the SAS System is limited to 1000 input
   observations.
   NOTE: SAS initialization used:
         real time           0.21 seconds
         cpu time            0.21 seconds
   1          /* show option nomacro set on invocation */
   2          data _null_ ;
   3             opt = getoption("macro") ;
   4             put opt= ;
   5          run ;
   opt=NOMACRO
   NOTE: DATA statement used:
         real time           0.01 seconds
         cpu time            0.01 seconds

   6
   7          %put I said no macro instructions! ;
              _
              _
              _
              180
              180
              180
   ERROR 180-322: Statement is not valid or it is used out of
   proper order.
   ERROR 180-322: Statement is not valid or it is used out of
   proper order.
   ERROR 180-322: Statement is not valid or it is used out of
   proper order.
   8          %inc "c:\junk\code1.sas" / source2 ;
   NOTE: %INCLUDE (level 1) file c:\junk\code1.sas is file
   c:\junk\code1.sas.
   9         +data w ;
   10        +   x = 1 ;
   11        +run ;
   NOTE: SAS set option OBS=0 and will continue to check
   statements.
         This may cause NOTE: No observations in data set.
   NOTE: The data set WORK.W has 0 observations and 1 variables.
   NOTE: DATA statement used:
         real time           0.01 seconds
         cpu time            0.01 seconds

   NOTE: %INCLUDE (level 1) ending.
   ERROR: Errors printed on page 1.
   ERROR: Errors printed on page 1.
   ERROR: Errors printed on page 1.
   NOTE: SAS Institute Inc., SAS Campus Drive, Cary, NC USA
   27513-2414
   NOTE: The SAS System used:
         real time           0.25 seconds
         cpu time            0.24 seconds

Note that the macro instruction %PUT could not be executed.
However, the non-macro instruction %INC did execute.
On the other hand, Paul is correct that %INC can be used on any
statement boundary.  Sometimes it can even be executed in the
middle of a SAS statement but not always.  For example, the line

   x = %inc "c:\junk\one.sas" ; + 1 ;

in a DATA step failed to compile.  However, the line

   if %inc "c:\junk\one.sas" ; then put "OK" ;

compiled and executed correctly. (ONE.SAS contains just the
number 1.)

I cannot comment on the propriety of saving Keith's IF block in a
file without seeing it.  However, there are many times that an IF
block could be better written some other way.

Paul's %INC suggestion is commensurate with the level suggested
by Keith's question.  Dare I face a dump from the MMMMM (macro
maven manure movers MONSTER) and suggest that this is the first
step to saving the code as a parameterized unit of SAS code?

Well maybe it is best postponed to the time Keith shows that
parameterization would be helpful to him.

Ian Whitlock
0
iw1junk (1187)
5/21/2005 11:54:36 PM
comp.soft-sys.sas 142828 articles. 3 followers. Post Follow

0 Replies
764 Views

Similar Articles

[PageSpeed] 37

Reply: