Window's Task Scheduler and %sysget Error

Accepted Solution Solved
Reply
Contributor
Posts: 34
Accepted Solution

Window's Task Scheduler and %sysget Error

  I am using Windows task scheduler to automatically run a large warehouse process (.bat file). The program executes as scheduled but there are errors when it runs as detailed by the log (no errors when run manually). The error that I am receiving is "the argument to macro function %SYSGET is not defined as a system variable." I can successfully run a simpler test program that only has one data step. Do I need to add a windows Environment Variable? I am by no means an expert when it comes to dealing with operating systems so please bear with me. Any help would be much appreciated.

Thank you,

Daniel


Accepted Solutions
Solution
‎06-18-2015 10:52 AM
Super User
Super User
Posts: 6,318

Re: Window's Task Scheduler and %sysget Error

That environment variable is set by the Enhanced Editor when using SAS on Windows.  It will NOT be set when running a program in some other environment.

Try %sysfunc(getoption(sysin)) instead.

View solution in original post


All Replies
Grand Advisor
Posts: 9,571

Re: Window's Task Scheduler and %sysget Error

Not Sure. Try

%sysfunc(sysget( SAS_EXECFILENAME )) ;

Contributor
Posts: 34

Re: Window's Task Scheduler and %sysget Error

I receive an error that the function is out of range when I try the above. Is there a character limit on %sysget? The problem seems to occur when I am referencing an external sas file via the %include command. Can I change system options somewhere to allow for longer strings?

Super User
Super User
Posts: 6,318

Re: Window's Task Scheduler and %sysget Error

What environment variable are you trying to retrieve using SYSGET?

Where do you think it is being set?

Most likely the set of environment variables that are created when the scheduled job is run are different than what you see when you use SAS normally.

Try using this data step to see what environment variables exist.

data _null_;

  infile 'set' pipe ;

  input;

put _infile_;

run;

Contributor
Posts: 34

Re: Window's Task Scheduler and %sysget Error

I am receiving the error when the program reaches %include statements where I load other program macros. I am just not well versed on the difference between running the program in batch and through the developer window. It was my understanding that when I run the sas.exe and then using the corresponding -sysin command to call the program, that it would be equivalent to opening BASE SAS and then running the program manually so I am not entirely sure why I am receiving these additional errors or even what exactly the purpose of %SYSGET is. I have included your above code and we will see how the program runs tomorrow. I'm also not entirely sure what "The infile ENVCMD is: Unnamed Pipe Access Device, PROCESS=set, RECFM=V,LRECL=1024" note means. I have read this paper:

http://support.sas.com/resources/papers/proceedings10/090-2010.pdf

but it hasn't helped much.

Thank you for answering Tom,

Daniel

Respected Advisor
Posts: 3,062

Re: Window's Task Scheduler and %sysget Error

My best guess is that you have a %SYSGET statement in one of the programs you are %INCLUDEing. Add the statement: options source2 mprint; to your program then run it.  Search the SAS log file for %SYSGET and post the statements and log errors for us to review.

Esteemed Advisor
Posts: 6,646

Re: Window's Task Scheduler and %sysget Error

%sysget is a macro function that retrieves the value of an environment variable.

In a windows command window, doing

echo %username%

will show the same as

%put %sysget(username);

in SAS.

So you need to look where %sysget is used (skim through the includes or use OPTIONS SOURCE2Smiley Wink, and which parameter (environment variable name) is supplied to the function. Then either change the SAS code or make sure in your .bat file that the environment variable is set to a correct value.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Valued Guide
Posts: 3,206

Re: Window's Task Scheduler and %sysget Error

That environment is delivered by the OS for each process. You can develop and test one with your personal user. If you trust the OS it would deliver the same environment with the task s cheduker you will be surprised as it is not.

The best usage is setting those env vars in an OS script.

By that you Sas code can be made  to run independent of dtap file naming conventions assumed alternate dates.

---->-- ja karman --<-----
Valued Guide
Posts: 3,206

Re: Window's Task Scheduler and %sysget Error

That environment is delivered by the OS for each process. You can develop and test one with your personal user. If you trust the OS it would deliver the same environment with the task s cheduker you will be surprised as it is not.

The best usage is setting those env vars in an OS script.

By that you Sas code can be made  to run independent of dtap file naming conventions assumed alternate dates.

---->-- ja karman --<-----
Contributor
Posts: 34

Re: Window's Task Scheduler and %sysget Error

Thank you everyone for the suggestions. I have dug deeper into some of the ancillary processes (not written by myself) and as pointed out above there is a call to determine the name of the current program using:

%let source_nm=%sysget(SAS_EXECFILEPATH);

where we see the original warning message. What I am trying to figure out is why I do not receive this warning when running manually but do receive it when I run using the scheduler. What is the best practice to declare a global OS environment variable so that I can run using the scheduler?

Thank you everyone for all your help. It is much appreciated!

Solution
‎06-18-2015 10:52 AM
Super User
Super User
Posts: 6,318

Re: Window's Task Scheduler and %sysget Error

That environment variable is set by the Enhanced Editor when using SAS on Windows.  It will NOT be set when running a program in some other environment.

Try %sysfunc(getoption(sysin)) instead.

Valued Guide
Posts: 3,206

Re: Window's Task Scheduler and %sysget Error

When you are using that environment variable to deduce a dtap indication with some logical constructs on naming conventions, it is better to work in the other way. Set those in the os start scripting and than deduce the namkng conventions.

This challenge is a never ending way of opinions until regulators will set guidelines. They are already doing that.

---->-- ja karman --<-----
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 11 replies
  • 394 views
  • 2 likes
  • 6 in conversation