1

I have setup a process that parallel processes 8 programs to pull a lot of data. However, I have to maintain all of the variables in each one going forward (this is a monthly thing).

Is there a way to create 1 master program with all of the variables and share them across programs when running? I understand each program uses its own instance of SAS so I am thinking no.

Nickolay
  • 31,095
  • 13
  • 107
  • 185
Jeff M
  • 23
  • 6
  • The programs can share a library. – data _null_ Aug 03 '19 at 13:39
  • hmmm...so I can create a permanent library (MYLIB) and assign a bunch of %let variables (MONTH, etc). How do I call them in my other programs? &MYLIB.MONTH? – Jeff M Aug 03 '19 at 14:04
  • Describe the variables in each of the 8 programs, and what you want as the final result. %LET variables are macro variables and can be considered more a parameters for controlling flow, code generation and data filtering values. Do you want to each of the 8 program to use the same macro variable values ? – Richard Aug 03 '19 at 14:19
  • I work for a data company and I am pulling down millions of records. I have to split the pulls into 8 different programs by product type so I do need all 8 programs to use the same %Let MONTH variable. I would love to do this once but it is more annoying than deal breaking if I can't. – Jeff M Aug 03 '19 at 14:22
  • Store the parameter values, like MONTH, in a dataset that is in the shared library. Each branch can then convert the value(s) from the parameter dataset into macro variable(s) if that helps the code. – Tom Aug 03 '19 at 16:08

1 Answers1

2

As you correctly notice, the different SAS programs do not share variables automatically, but you can pass them explicitly:

  • By passing them through environment variables (this is especially useful when you have few parameters, like the report date).

    • The launcher program in this case can be a simple shell script, e.g. in *nix:

      export REPORT_DATE=20190701
      sas -sysin program_a.sas
      
    • Or, from SAS, you can use systask command to execute the child SAS session
    • From the child session you can retrieve the parameter value via %sysget:

      %let REPORT_DATE = %sysget(REPORT_DATE);
      
  • As suggested in the comments, by storing the parameters in a shared location (e.g. in a dataset).

    • In the parent session:

      data sharedlib.params;
          REPORT_DATE = "&REPORT_DATE";
      run;
      
    • In the child session:

      proc sql noprint;
          select REPORT_DATE /*format XXX. as necessary*/ into :REPORT_DATE
          from sharedlib.params;
      quit;
      
  • If you use SAS/CONNECT to manage the child sessions (i.e. signon and rsubmit), you can pass the variables via %sysrput

Nickolay
  • 31,095
  • 13
  • 107
  • 185