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

Thanks Ian.

I actually switched it over to a %include since readability is critical
here. The only other method I can think of is to use datalines but that is
not as convenient either.

The underlying problem behind this exercise was:

How can I have a set of valid SAS statements be filed into a text file and
also be available for execution?

Immediately, I said %include since that is obvious. However, I was hoping to
also be able to see the lines and make quick modifications in the editor.
Since I have had time to think about it some more, I decided to go ahead and
split it out into 2 programs and simply %include them. That way I retain
formatting. The only negative is that they are now in 2 tabs but I can live
with that.

All of the exploration done by people and pointing out various options has
been helpful. The formatting though is critical and I don't want to run my
cleaner on it.

Sometimes it is best to just KISS.


Alan Churchill

-----Original Message-----
From: iw1junk@comcast.net [mailto:iw1junk@comcast.net]
Sent: Tuesday, August 12, 2008 10:29 AM
To: SAS(r) Discussion
Cc: Alan Churchill
Subject: Re: Include SAS code w/o including SAS code

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 >
savian001 (795)
8/12/2008 4:38:11 PM
comp.soft-sys.sas 142827 articles. 4 followers. Post Follow

0 Replies

Similar Articles

[PageSpeed] 38