I'm trying to pass an -emailid $emailid in my sasv9_local.cfg, I set the environment variable in the sasenv_local, and it is defintiely running and exporting the variable.
If I run this from SAS Enterprise Guide, it runs as expected.
If I run this from batch command line it won't use the environment variable, it just leaves emailid as the literal $emailid.
Is this a bug or intentional?
My full fix is below, I was hoping to skip the autoexec.sas and just do it in the sasv9_local.cfg with the -emailid = $emailid.
This allows the system to set the user's proper FROM address instead of using a generic address and making users set it in their mail statement. We set a default for service accounts that don't have individual email addresses.
In !SASROOT/bin/sasenv_local
# Set default email
emailid="noreply@ourdomain.com"
# Path to the lookup file
lookup_file="/userid_email_lookup.txt"
# Read the file and find the matching email
while IFS='|' read -r user_id field2 email rest; do
if [[ "$user_id" == "$USER" && -n "$email" ]]; then
emailid="$email"
break
fi
done < "$lookup_file"
# Optionally export it for use in other scripts
export emailid
In sasv9_local.cfg
-autoexec !SASROOT/autoexec.sas
In !SASROOT/autoexec.sas
options emailid="%sysget(emailid)";
Thanks everyone for the participation!
You'll need to apply the change in your SASApp folder to sasv9_usermods.cfg for this to also work for batch jobs.
How do you execute SAS batch jobs then? The typical practice is to execute the sasbatch script that would be in /sasapp/batchserver in which case it will pick up SASApp modifications.
I suggest you try the sasbatch script as otherwise you will miss out on any config modifications.
You need to set this environment variable at command line .
For example, if you want environment variable SAS_EXECFILEPATH has value "c:\sascode\" :
"D:\SASHome\SASFoundation\9.4\sas.exe" -nosplash -sysin "c:\temp\temp.sas" -set SAS_EXECFILEPATH "c:\sascode\"
Check @Rick_SAS blog:
How to pass parameter into SAS programm:
https://blogs.sas.com/content/iml/2015/03/16/pass-params-sysget.html
My full fix is below, I was hoping to skip the autoexec.sas and just do it in the sasv9_local.cfg with the -emailid = $emailid.
This allows the system to set the user's proper FROM address instead of using a generic address and making users set it in their mail statement. We set a default for service accounts that don't have individual email addresses.
In !SASROOT/bin/sasenv_local
# Set default email
emailid="noreply@ourdomain.com"
# Path to the lookup file
lookup_file="/userid_email_lookup.txt"
# Read the file and find the matching email
while IFS='|' read -r user_id field2 email rest; do
if [[ "$user_id" == "$USER" && -n "$email" ]]; then
emailid="$email"
break
fi
done < "$lookup_file"
# Optionally export it for use in other scripts
export emailid
In sasv9_local.cfg
-autoexec !SASROOT/autoexec.sas
In !SASROOT/autoexec.sas
options emailid="%sysget(emailid)";
Thanks everyone for the participation!
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.
Ready to level-up your skills? Choose your own adventure.