BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
RobertWF
Calcite | Level 5

Hello,

I'm running a series of SAS programs which calculate bootstrap confidence intervals. In order to cut the run time, I'm running a series of programs in a timed sequence, with 5 bootstrap programs running simultaneously:

data_prep -> bootstrap1 & bootstrap2 & bootstrap3 & bootstrap4 & bootstrap5 -> compile_results

It would be awesome if I could declare a macro variable only once, say in the initial data_prep program, and then pass on the value of that macro variable to the subsequent programs rather than having to "hard code" the macro variable value in each bootstrap program. The fewer parameters I have to tweak the fewer errors I'll make. Is it possible to create global macro variables with inter-program scope?

Any thoughts/suggestions are welcome!

Thank you,

Robert

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

If they are run in the same SAS session global macro variables will be available in any program.

I use this approach to set a date stamp string in a specific format in my AUTOEXEC.SAS file so it doesn't have to be created in each program.

View solution in original post

8 REPLIES 8
ballardw
Super User

If they are run in the same SAS session global macro variables will be available in any program.

I use this approach to set a date stamp string in a specific format in my AUTOEXEC.SAS file so it doesn't have to be created in each program.

RobertWF
Calcite | Level 5

Great, thank you - will global macro variables work when running my programs in batch mode from Unix?

Ksharp
Super User

It looks like you are looking for system options SYSPARM= .

SYSPARM Details

The value of the SYSPARM automatic macro variable is the same as the value of the

SYSPARM= system option, which is equivalent to the return value of the SAS language

function SYSPARM. The default value is null. Because you can use the SYSPARM=

system option at SAS invocation, you can set the value of the SYSPARM automatic

macro variable before your SAS session begins.

Ksharp

RobertWF
Calcite | Level 5

Thanks Ksharp, the -SYSPARM option worked well as a command line option when running individual SAS programs in batch mode:

>>sasb bootprogram1 -sysparm 100

where the value of "100" is passed on to the sample size variable in my bootstrap program:

%let numsamp=&sysparm;

When running multiple SAS programs in a shell script, I noticed the SYSPARM option has to be added to each program in the script text file rather than on the actual command line.

So executing:

>>shell.sh -sysparm 2

where shell.sh contains

sasb bootprogram1 & sasb bootprogram2

does not execute properly, but

>>shell.sh

where shell.sh contains

sasb bootprogram1 -sysparm 2 & sasb bootprogram2 -sysparm 2

does work.

Robert

Tom
Super User Tom
Super User

Store your parameters in a file or dataset.  Then each job can read them from there.

If you use a CSV text file then you can do something like:

data _null_;

  infile 'parms' dsd ;

  length name $32 value $200;

  input name value;

  call symputx(name,value);

run;

If you use a dataset then you can do something like:

data _null_;

  set 'parms.sas7bdat';

  call symputx(name,value);

run;

Ksharp
Super User

Yes. system options SYSPARM= is a SAS system option ,not UNIX system option.

But you can set its value in AUTOEXEC.SAS . so everytime start a sas session ,sas will take care of this option.

data_null__
Jade | Level 19

You can use SYSGET to retrieve the value of a system/environment variable.    There is a macro and a data step version of the function.

%SYSGET 

returns the character string that is the value of the environment variable passed as the argument. Both UNIX and SAS environment variables can be translated using the %SYSGET function. A warning message is written if the global variable does not exist. Here is the form of the %SYSGET function:

%SYSGET(environment-variable);

For example, the following code writes the value of the HOME environment variable to the SAS log:

%let var1=%sysget(HOME);  %put &var1;
data_null__
Jade | Level 19

I expect you don't need to run multiple jobs to speed up your bootstrap.  I think you just need to fix it to work better/faster.  Start a new thread we will have lots of fun fixing it.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 8 replies
  • 1484 views
  • 3 likes
  • 5 in conversation