Compiling SAS programs

Reply
Occasional Contributor
Posts: 18

Compiling SAS programs

Hi all.


I would like to know if there is a way to distribute a SAS program without
actually sharing the code with others. Basically, I want to preserve the
proprietary knowledge of a method I developed until I have a chance to

publish it in a journal. I though I heard or read somewhere that you can

compile a SAS program. Can someone provide me with a little guidance

(and snippet of code) on how to do this. My program is written in the SAS

macro language, so basically users only need to provide the name of

a SAS file and the program will produce the analysis for them.


thanks,
Cristian

Respected Advisor
Posts: 3,887

Re: Compiling SAS programs

Occasional Contributor
Posts: 18

Re: Compiling SAS programs

Hi Patrick,

Thank you for your reply. I had a chance to implement the solution you proposed this week. It is consistent with what I was looking for. However, I have run into a few small hiccups along the way. Some of my students, to whom I am distributing the sasmacr file, are unable to read it. SAS is giving them a message like

ERROR: File
TMP3.SASMACR.CATALOG was created for a different operating system
”. And
An error occurred attempting to initialize a SAS
desktop object from class sashelp.sasdesk.catmodel
.”

How do I resolve this?

best,

Cristian

Frequent Contributor
Posts: 129

Re: Compiling SAS programs

Hi Cristian,

Stored compiled macro procedures are not executable on operating systems different from where they were compiled.

So my guess is you have some students trying to run on a different OS than the one in which you compiled the code. Check what OS the students with errors are using.  Then you may have to re-compile the macro library on that OS.

Larry

Occasional Contributor
Posts: 18

Re: Compiling SAS programs

Hi Larry,

By different OS do you mean 64-bit versus 32-bit? Or Windows 7 versus another version? What about SAS versions? My students either have 9.13, 9.2, or 9.3 on their PCs. Do I need to compile on different versions of SAS as well as OS? If so, has SAS not come up with another solution for distributing programs that protects intellectual rights?

Cristian

Frequent Contributor
Posts: 129

Re: Compiling SAS programs

Cristian,

Here is snippet i found in the SAS 9.2 Macro Language Reference,http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a001328775.htm.

You cannot move a stored compiled macro to another operating system. You can, however, move the macro source code to another operating system where you can then compile and store it. You might need to recompile these macros if you use them in a different release of SAS. For more information, see your host companion.

As you can tell from that statement, the institute is not very specific about what they mean.  I would expect difference between 32-bit and 64-bit OSs and am less inclined to expect differences between the different 32-bit windows os.  Also  I do not expect difference between the different flavors of SAS9.x, but still a possibility.

I would suggest looking for patterns of differences of your students' OS(including 32 vs 64bit) and SAS version to what you compiled the macros  I expect you will be able to detect the relevant differences.  Then hopefully you would find one system configuration you need to re-compile on.

You might also check with SAS Tech support.  Using the site, http://support.sas.com/ctx/supportform//createForm, you can do that either on line or by telephone.  They might be able to be more specific about the system incapatibilities but I suspect they will send you done the same path I am.

Larry

Occasional Contributor
Posts: 18

Re: Compiling SAS programs

Hi Larry,

I've been using the SAS macro library for a couple of weeks. A few small headaches along the way, but I've been able to resolve them. However, I ran into a problem tonight that I would like a little help with. Now that I know how to securely compile my code, I am trying to secure more programs so that I can distribute them to my students. Recently, I was working with the following code. In order to keep my program short, I am referring my source code, which is located in separate files. The problem with this is that students will have a different file/folder structure on their computers. Hence, the code fails. I know that I can simply paste the actual code inside the macros. However, since I am trying to build a library of macros, over time, sorting through all the pages of code will be cumbersome. Do you have any suggestions for resolving this?

best,

Cristian

%Let Loc1=E:\Ohio State University\Teaching\Introduction to Educational Measurement\Fall 2012\;

options mstored sasmstore=mylib;
libname mylib "&Loc1\Secure macros\32-bit OS";

%macro DiscreteCI(DS=,Var=,alpha=,popN=)/store secure; /* This macro is encrypted */
     ods html close;
     ods listing;
    OPTIONS nodate NONUMBER nonotes nosource errors=0 NOPRINTMSGLIST linesize=102 pagesize=62; * Abbreviate size of log file ;
     %Include "&Loc1\Secure macros\Source macro code\Median CI for a single discrete variable.sas" ;  /* Run external SAS code */
%mend DiscreteCI;

%macro ContinuousCI(DS=,Var=,alpha=,popN=)/store secure; /* This macro is encrypted */
     ods html close;
     ods listing;
    OPTIONS nodate NONUMBER nonotes nosource errors=0 NOPRINTMSGLIST linesize=102 pagesize=62; * Abbreviate size of log file ;
    %Include "&Loc1\Secure macros\Source macro code\Median CI for a single continuous variable.sas" ;  /* Run external SAS code */
%mend ContinuousCI;

Super User
Super User
Posts: 6,497

Re: Compiling SAS programs

I do not understand what you are saving by using %INC statements?

Also why is it defining a macro named continuousci but storing the code in a file named "Median CI for a single continuous variable.sas"?  That just sounds like an invitation to generate mistakes caused by confusion. But since the thread starts off with looking for a method to hide the code then perhaps confusion is what is wanted?

Occasional Contributor
Posts: 18

Re: Compiling SAS programs

Hi Tom,

I wanted to use the %Inc statements to save space in the program that generated the SAS macro library. Some of the programs I wrote are several pages long. One is close to 30 pages long. I was not tying to be deceptive with my names. I developed a way for constructing nonparametric CI on the median for continuous data. SAS actually also can do this using Proc Univariate. However, our search algorithm for the order statistics are different. My method occassionally produces a tighter CI than existing methods. Hence, I called the macro ContinuousCI, so as to distinguish it from the DiscreteCI method. I derived the formula for constructing a nonparametric CI on discrete, including ordinal, data. Thus, I called the macro DiscreteCI. No one has ever derived a solution for this problem. Hence, my interest in protecting the source code until I publish the method.

So, if there a solution to the %INC problem or do I have not choice but to include that source code in the program that creates the SAS macro library?

best,

Cristian

Respected Advisor
Posts: 3,887

Re: Compiling SAS programs

Is this how you compile the macros for yourself or is this the code you are handing out to your students?

If this is the code you're handing out: Using an %include won't protect your code as students will be able to directly access the code via the file path. Or simply use "options source2;" and it shows up in the log.

The only way is to pre-compile the code as secure macros and distribute the macro catalog. And as we know: It must be compiled for the OS SAS is running under.

The easiest way for you would be if all your students would run your stuff in the same environment so you would simply have to maintain a single macro store accessible to everyone. Not sure how your Uni is organised but it might be worth to investigate such a setting. Another option is SAS on Demand to have this common environment. I'm not sure how it exactly works and if it's an option for you, but it's sure worth to consider http://www.sas.com/govedu/edu/programs/od_academics.html

Super User
Super User
Posts: 6,497

Re: Compiling SAS programs

If the goal is to make the compilation easy then you can just use a single %INCLUDE statement.

Say your macros are in the directory C:\macros then you just need to use:

%include "c:\macros\*.sas" ;

Occasional Contributor
Posts: 10

Re: Compiling SAS programs

crisgugiu,

The macro store is the most effective way to store your code and hide the code.  However, if you want to save the code, you can do what I do so when I ship updates, I send over one sas7bcat file isntead of a zipped file of the code.

There are two ways to store SAS code to a catalog.  You can either store each data step in a SAS catalog (big pain), or you can load an entire program to a SAS catalog.  Unlike storing SAS Macros to the macro catalog where the Macro catalog is set as a libref, set the catalog as a fileref (i.e., filename fileref "path").  There are two ways to do this:

  1. Write the program to the file:
    1. libname catlib "path-to-catalog";
      filename catfile catalog "catlib.project";
      data _null_;
         file catfile(filename.source);
          put "data newdata;";
          put "    set olddata;";
          put "  * some more datasteps;";
          put "run;";
      run;
  2. But, since I'm lazy and it's not as simple to test programs that way and make adjustments:
    1. libname catlib "path-to-catalog";

      filename catfile catalog "catlib.project";
      filename includes "my include library"; /* it's already set up, but for clarity, I've included it here */
      data _null_;
          file catfile(filename.source);    /* note the ".source" - need that so it can be used in an include */
          infile includes(filename.sas);  /* note - the ".sas" is needed where the OS requires it to work */
          input;

          put _infile_;
      run;

With the second step, filename should be the same for both the input and output so when you include it in code later on, your code doesn't break.

So you know, I get a listing of all the files in the include library first, then use a macro to loop through the list and build my source catalog.  Later, when you use the catalog, do the following:

libname catlib "path-to-catalog";

filename catfile catalog "catlib.project";

%include catfile(filename);

You can prevent the actual source code from being viewed in the process by creating a macro that stores the current options, sets options nosource nosource2;, then re-stores the options to what they were.  If you want to go to the trouble.

#

Ask a Question
Discussion stats
  • 11 replies
  • 2956 views
  • 0 likes
  • 5 in conversation