BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Anacreo
Obsidian | Level 7

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Anacreo
Obsidian | Level 7

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!

View solution in original post

8 REPLIES 8
SASKiwi
PROC Star

You'll need to apply the change in your SASApp folder to sasv9_usermods.cfg for this to also work for batch jobs.

Anacreo
Obsidian | Level 7
The Unix command line isn't aware of the SASApp / Lev1 structure, it does pickup the setting in !SASHOME/SASFoundation/9.4/sasv9_local.cfg but it won't resolve the $emailid, it keeps it as a literal.

$ grep emailid SASFoundation/9.4/sasv9_local.cfg
-emailid $emailid

However if I run this sas code from Unix:
%PUT MY_ENV_VAR = %SYSGET(emailid);

I can see that emailid is being set by the sasenv_local (also a debug file is outputted).

It works correctly in a SAS EG.
SASKiwi
PROC Star

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.

Anacreo
Obsidian | Level 7
We will just execute !SASHOME/SASFoundation/9.4/bin/sas mysascode.sas
SASKiwi
PROC Star

I suggest you try the sasbatch script as otherwise you will miss out on any config modifications.

Anacreo
Obsidian | Level 7
We have a large configuration, I can definitely investigate it, but we're not setup that way today. Would like to get the original problem solved.
Ksharp
Super User

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

 

Anacreo
Obsidian | Level 7

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!

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 933 views
  • 3 likes
  • 3 in conversation