The gist of the issues is this. I need to run my SAS programs that send emails on a schedule. I acomplished this through BAT files, SAS script and the Windows task scheduler. I need to improve the program by being able to eliminate hard coded Passwords and UserIDs (Prefix to email).
Using Proc PWENCODE I have successfuly placed in my Password was able to feed it into the PWD= option in the OPTIONS EMAILHOST() line.
My problem is that i thought i could do the same with my email:
Proc pwencode in="Test@uni.edu" method=SAS004; Run;
This provides me a sting just like it does for the Password. ^^^ %let User=%str({SAS004}*****); ^^^
When I pass the macro into the userid field it does not work. It says that the email server is not available. If i hard code it, or use a macro variable that is not endoded (*%let user=Test@uni.edu; ) it will work.
Does the Proc PWEncode and its subsequesnt uses only apply to options that SAS deems as a "Password"? Can I not Encode any string and resolve it just like a macro variable?
Has anyone passed an encoded string to a filed that isnt a password?
NOTE: I found that i can not encode the first part of my email (TEST) and concatenate it to the second half (@uni.edu) because of the timing at which the encoding resolves and that fact that there are quotes keeping it from concatenating. It has to be encoded and resolved all toegether.
proc pwencode in="Test@uni.edu" method=sas004;
run;
proc pwencode in="BIGpassWorD" method=sas004;
run;
%include "SAS File That constains";
/********************************************************/
/*%let NET=%str({SAS004}***********);*/
/*%let PWD=%str({SAS004}************);*/
/*********************************************************?
%let User2=Test@uni.edu;
%macro Stats_Email;
options emailsys=smtp;
options emailauthprotocol=login ;
options emailhost=('smtp.office365.com'
port=587
starttls
auth=login
pwd="&PWD" /* This works */
userid="&NET" /* This does not work*/
userid=&User2. /* This works*/
userid=Test@uni.edu /* This works*/
);
filename Mymail email
from='Test@uni.edu'
type='TEXT/HTML'
;
data _null_;
file Mymail
subject="SUBJECT"
to=( &Recipients. )
;
put 'BODY';
run;
ods html close;
%mend;
%Stats_Email;
I think the answer to your key question:
Does the Proc PWEncode and its subsequesnt uses only apply to options that SAS deems as a "Password"? Can I not Encode any string and resolve it just like a macro variable?
Is YES. PWENCODE is for encoding passwords. And when you pass an encoded string to a Password, SAS will decode it for you and everything works. But if SAS does not know it's a password, it will not decode it.
It's not a general purpose tool like macro variable resolution.
If I encode the string the string sashelp.class I get:
12 proc pwencode in=XXXXXXXXXXXXXXX ; 13 run ; {SAS002}CF1B9B3C5ADB2411174A853C492D86242B2852DA51F0DCB8
But I cannot then code:
data want;
set {SAS002}CF1B9B3C5ADB2411174A853C492D86242B2852DA51F0DCB8 ;
run;
When the DATA step is compiled, the value won't be decoded.
Looking at it now, I can see you might think it would work. They could have designed it so that the string string {SAS002} was a general trigger which means "decode the next value", in the same way that the & is a general trigger to resolve a value. And then you could use it to encode any text that appears in your code. But that is not the way that PWENCODEd values work. They are only decoded when SAS knows the value is a password.
I think the answer to your key question:
Does the Proc PWEncode and its subsequesnt uses only apply to options that SAS deems as a "Password"? Can I not Encode any string and resolve it just like a macro variable?
Is YES. PWENCODE is for encoding passwords. And when you pass an encoded string to a Password, SAS will decode it for you and everything works. But if SAS does not know it's a password, it will not decode it.
It's not a general purpose tool like macro variable resolution.
If I encode the string the string sashelp.class I get:
12 proc pwencode in=XXXXXXXXXXXXXXX ; 13 run ; {SAS002}CF1B9B3C5ADB2411174A853C492D86242B2852DA51F0DCB8
But I cannot then code:
data want;
set {SAS002}CF1B9B3C5ADB2411174A853C492D86242B2852DA51F0DCB8 ;
run;
When the DATA step is compiled, the value won't be decoded.
Looking at it now, I can see you might think it would work. They could have designed it so that the string string {SAS002} was a general trigger which means "decode the next value", in the same way that the & is a general trigger to resolve a value. And then you could use it to encode any text that appears in your code. But that is not the way that PWENCODEd values work. They are only decoded when SAS knows the value is a password.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.