Re: Include SAS code w/o including SAS code #10

Summary: Macro generation of correct SAS code requires SAS execution.


I do not see how this is possible.


   %macro q ( seed=0 ) ;
      %local cum ;

      data w ( keep = r ) ;
        do i = 1 to 20 ;
           r = ranuni ( &seed ) ;
           output ;
        end ;
      run ;

      data _null_ ;
         set w end = eof ;
         cum + r ;
         if eof then
            call symputx ( "cum" , cum ) ;
      run ;

      title1 "Cum = &cum" ;
   %mend  q ;

This macro ends up generating a TITLE statement.  However, that
title statement depends on the execution of the previous steps.
Hence it cannot be generated by the macro facility without actually
executing the previously generated code.

The problem is similar to that of using CALL EXECUTE to generate
SAS code via a macro call.  In the case of CALL EXECUTE one can work
around the problem by using %NRSTR to hide the call during the DATA
step execution, but you have explicitly required the macro to generate
correct code without executing.  Now there is no work around.

In essence you are asking, "Is the macro facility so weak that there
is a program that can predict the output of every macro without
executing it?"  Since that output can depend on the execution of SAS
code, one must first be able to predict the result of executing every
SAS program without actually doing the executing.  It seems highly
unlikely that the SAS Institute is up to the job.

Now in the simple situation that you gave, you could use the MFILE
option with OBS = 0, and one of your "make SAS code pretty" programs
to achieve a result almost as good as not executing SAS.

The thing that is interesting about my above code is that no macro
instructions other than asigning and evaluating macro variables are
used.  So even in this simple setting it might be hard to predict
whether the resulting SAS code is the same as it would have been had
the generated code actual executed.

Ian Whitlock
Date:         Tue, 12 Aug 2008 08:41:35 -0600
Reply-To:     Alan Churchill <savian001@GMAIL.COM>
Sender:       "SAS(r) Discussion"
From:         Alan Churchill <savian001@GMAIL.COM>
Subject:      Re: Include SAS code w/o including SAS code
Comments: To: "Fehd, Ronald J. (CDC/CCHIS/NCPHI)" <rjf2@CDC.GOV>
Content-Type: text/plain; charset="us-ascii"

I actually never want to store the macro code. I only want it
available in a temp file which I then consume. For example:

%macro xyz;
   data temp.temp4;
     ...do some sas stuff...

I want to save the contents, formatted, into a text file (i.e.
c:\temp\program.sas) which I can then consume in another application.
I also want to execute the code. Hence:


Save the contents of the macro file to a text file with CRLF included.
I don't want the run, merely the statements.



Alan Churchill Savian www.savian.net

<snip >
iw1junk (1187)
8/12/2008 4:28:40 PM
comp.soft-sys.sas 142827 articles. 4 followers. Post Follow

0 Replies

Similar Articles

[PageSpeed] 16