BookmarkSubscribeRSS Feed
Walternate
Obsidian | Level 7

Hi everyone,

 

I have a program which uses the macro variable &num to do a bunch of stuff (the purport of the program is not really relevant to my question). &num is set by hand. 

 

I want to set up some automated runs of my program. I know how to do this, but my question is this: I'll be doing lots of runs of the program and changing &num each time (but not making any other changes). Is there a more efficient way to set this up than:

 

1. Make manual change to &num

2. Let automatic run happen as scheduled

And repeat this process for each new instances of &num?

 

Any help is much appreciated!

8 REPLIES 8
PaigeMiller
Diamond | Level 26

Just one macro variable, that's all that changes?

 

What determines in your mind (not in SAS) what the value of &num will change to?

--
Paige Miller
Walternate
Obsidian | Level 7

The program processes files and &num is in the file name.

PaigeMiller
Diamond | Level 26

@Walternate wrote:

The program processes files and &num is in the file name.


I don't think this answers my questions.

--
Paige Miller
Reeza
Super User

@Walternate wrote:

The program processes files and &num is in the file name.


The generated file name? Or the input file name? Does it follow an increment schedule? Randomly assigned? Or magically assigned?

ballardw
Super User

Where to do the "new instances of &num" come from? Are these values in a data set? Based on a calendar date? The phase of the moon? Armenian Fiscal Years?

 

Without knowing where values for &num come from there is no way this can be automated.

 

 

Walternate
Obsidian | Level 7

I receive input files to be processed by the program and &num is in the name of the input file, eg: Listing of files in directory &num.xlsx . 

 

 

PaigeMiller
Diamond | Level 26

So are you saying that you receive a file, here is a possible name of the file:

 

Listing of files in directory 16.xlsx

 

And then in your program you want to use 16? 

 

Is this Excel file in a specific folder, where its name can be read by your program and parsed? Are there ever other Excel files in that folder? 

 

Please explain the process by which this file is found in detail, rather than have us ask lots of questions. Don't be brief with your explanations, don't be stingy with information. We're trying to help you but you have to help us.

--
Paige Miller
Kurt_Bremser
Super User

SAS provides several ways to pick up data from the "outside".

You can add

-sysparm="string"

to the commandline and then use the SYSPARM function or the &SYSPARM automatic macro variable.

Or (and this is what schedulers do) set environment variables and retrieve those with the SYSGET data step function or %SYSGET macro function.

Script file (if on UNIX)

export NUMBER=16
sas program.sas

In the program,

%let number = %sysget(NUMBER);

will set the macro variable number to 16.

On Windows, use the set command in the batch file.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 1808 views
  • 1 like
  • 5 in conversation