Reputation: 12515
I have the following code:
%let my_var = %sysget(MY_VAR);
%put &=my_var;
If I run the following code, my_var
will be defined and print:
#!/bin/bash
export MY_VAR=1;
/sas/scripts/sas my_script.sas
But without that export
statement, my_var
is effectively not defined, and the script fully executes, without error.
#!/bin/bash
/sas/scripts/sas my_script.sas
I want to set a default value for what's returned from %sysget
in case the variable isn't defined. How can I do that?
Upvotes: 1
Views: 261
Reputation: 51601
You can use the ENVLEN() function to find the length of an environment variable. It will return -1 when it is not defined.
%let vname=MY_VAR;
%let want=DEFAULT;
%if %sysfunc(envlen(&vname))>-1 %then %do;
%let want=%sysget(&vname.);
%end;
%put &=vname &=want;
Upvotes: 3