BookmarkSubscribeRSS Feed
dphilip01
Fluorite | Level 6

HI SAS DI Community,

 

I'm a long time SAS user that has worked several years with SAS-PC and SAS EG. I recently started working with SAS DI Studio.  4.9. SAS DI is definitely a different animal from it's predecessors. Long story short, There has been a couple of months to learn this IDE.

One of the tools that I liked in other SAS tools, was the ease of creating an using an "Include file" to store commonly used macros..

 

I've looked at the "User Written Code Transformation" in SAS DI but, I'm not sure if this is the best way to ijmplement an include file.  I'd greatly appreciate it, if anyone out there has found the best way to implement an include file in SAS DI or is aware of a good online reference that would clearly explain this task.  

 

Thank you very much,

 

DPhilip01

3 REPLIES 3
ErikLund_Jensen
Rhodochrosite | Level 12

Hi @dphilip01 

 

In my opinion commonly used macros should not be loaded in a transformation, they belong in the autocall macro library, so they are available to all jobs executing in the server context. Locate the sasv9_usermods.cfg file and insert lines to add the directories containing macros like this example:

 

-insert sasautos "/sasdata/prod/makro/applications"
-insert sasautos "/sasdata/prod/makro/common"

 

If you have other server contexts for SAS EG, DI Studio Development or whatever, it's a good idea to motify these as well, so the macros are available everywhere.

 

Of course it can be done with a transformation in DI Studio too, but the User Written Transform is not a good choice because you would need to write the include statement in the code pane in all instances of the transformation, i.e. in all jobs,  and store it as step code. 

 

It would be easier to write a user transformation with a prompt for the file to include (full path) and set the preferred includecode as default value to the prompt. The result would be a new transformation to pull into the job canvas, where it would run without any local modifications. Remember to set the control flow order so it runs as no. 1. 

 

It would look like this on the canvas:

 

 

ic.gif

 

 

 

 

 

 

 

 

 

and generate this code:

 

/*==========================================================================* 
 * Step:            Includecode                           A580FNM8.BV000P3N * 
 * Transform:       Includecode                                             * 
 * Description:                                                             * 
 *==========================================================================*/ 

%let transformID = %quote(A580FNM8.BV000P3N);
%let trans_rc = 0;
%let etls_stepStartTime = %sysfunc(datetime(), datetime20.); 

%let _INPUT_count = 0; 
%let _OUTPUT_count = 0; 

%let includecode = %nrquote(/sasdata/prod/makro/applications/commonmacros.sas);

%include "&sourcefile";
run;
%rcSet(&syserr); %rcSet(&sysrc); %rcSet(&sqlrc); /** Step end Includecode **/

Let me know If you are unfamiliar with userwritten transformations and want some guidance to get started.

Patrick
Opal | Level 21

I'd definitely go for autocall macros. Because it's often not possible to modify the config/autoexec one approach I'm using:

Either store the autocall macros in an already pre-defined macro folder or create a custom transformation (file/new/transformation) with code as below which adds a path the the SASAUTOS option. Then use this custom transformation always as first node in any DIS job.

 

%macro addAutocallPath(path=);
  %local addpath;
  %let addpath=0;
  %put AA: %sysfunc(getoption(sasautos,expand));
  data _null_;
    if findw(getoption('sasautos','EXPAND'),"&path",'. ','tkfd')<=0 then
      do;
        call symputx('addpath','1','l');
      end;
  run;
  %if &addpath=1 %then
    %do;
      options insert=(sasautos="&path");
    %end;
  %put BB: %sysfunc(getoption(sasautos,expand));

%mend;
%addAutocallPath(path=<path>/SASMacro)

 

 

I then keep the code for any other environment specific definitions like paths in an "%init" macro which I also call directly via above custom transformation (normally implemented via prompt which I then just resolve in the code bit).

 

I'd define macro variables for any paths via this %init macro. 

Something like:

%let lev=Lev1;

%let myapp_path=/opt/sas/..../&lev/apps/myapp;

 

If you then still want to use include statements (not for macro calls though) they could then look like:

%include "&myapp/code/myprog.sas" / source2;

 

Doing it this way will allow you to move whole applications (i.e. from Lev2 to Lev1) but you only need to apply the change in a single %init() macro (or a config text file which the %init macro then processes to create macro variable).

 

BTW: I normally try to make my case and have the &lev macro variable defined in the autoexec. You could also make this bit dynamic by querying the environment like for the path to the app server you're using and then pull out the environment from there.

 

 

dphilip01
Fluorite | Level 6
Thank you very much for taking the time to answer my question regarding the implementation

of an include file in SAS DI Studio. I'm looking into the macro auto call facility as you suggested.



Have a nice day,



Darryl


sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 634 views
  • 1 like
  • 3 in conversation