Hello, I am looking to auto populate some fields that I currently need to manually enter each time. I would like to do this in order to run some code automatically each day.
Is it possible to auto populate the fields in the attached image?
Hey, yes, you can simply put your credentials in an authinfo file and then specify the key for that in your config. See the doc here:
https://sassoftware.github.io/saspy/install.html#iom-using-java
and scroll down to the authinfo part. Well, I'll cut-n-paste that next. You use the 'authkey' in your configuration definition to specify which credentials to use. You can have different credentials for different connections.
The IOM access method now has support for getting the required user/password from an authinfo file in the user’s home directory instead of prompting for it. On linux, the file is named .authinfo and on windows, it’s _authinfo. The format of the line in the authinfo file is as follows. The first value is the authkey value you specify for authkey. Next is the ‘user’ key followed by the value (the user id) and then ‘password’ key followed by its value (the user’s password). Note that there are permission rules for this file. On linux the file must have permissions of 600, only the user can read or write the file. On Windows, the file should be equally locked down to where only the owner can read and write it.
authkey user omr_user_id password omr_user_password
So, for a Configuration Definition that specifies the following authkey:
'authkey' : 'IOM_Prod_Grid1',
The authinfo file in the home directory for user Bob, with a password of BobsPW1 would have a line in it as follows:
IOM_Prod_Grid1 user Bob password BobsPW1
Thanks,
Tom
You could put the username and password into a CONFIG file and import them. Then pass them as parameter values in the saspy statement. You should also be able to pass the SAS config parameter as well:
# first create a file in CONFIG directory within home directory called sasconfig where: # username = 'userid' # password = 'password' import saspy from CONFIG.sasconfig import username, password sas = saspy.SASsession(omruser=username, omrpw=password, cfgname='<sas_config_here>')
Thank you! This worked!
Now it also prompts me for this info when I do my first SAS data pull. How do I auto populate that information in that section?
Example
%%SAS
proc sql;
create table x as
select *
from somewhere;
quit;
If you used the authinfo file for your credentials, that saspy supports, this would work too.
Tom
I'm sorry for my ignorance, but how would I put that in the SAS code chunk?
I tried this, and it still prompted me.
%%SAS
%let omruser=username;
%let omrpw=password;
%let cfgname='sasfusionint';
proc sql;
create table x as
select *
from somewhere;
quit;
Hey, I'm a little confused. saspy has a way for you to store credentials in a secure file so that you don't need to do any of the things you're trying to do, based upon the other users suggestion, which was basically, try to implement that yourself. That was a fine idea, except there's no need, and trying to implement it yourself doesn't get you working when trying to use the magic.
Did you see my post about the authinfo file, with the instructions and the link to the documentation? If you put your credentials in the authinfo file, then saspy will just work without prompting you for all cases. And you don't need to write special code to try to implement it yourself.
Two other things worth noting. the magic creates its own SASsession to use. That was the default behavior when it was originally implemented. Since then it was enhanced to take a SASsession object and use that session to submit the code.The magic just calls the submit() method and displays the LST, if there is one, else the LOG.
In the current release, V3.1.8, there are two new variants of the submit method; submitLOG() and submitLST() (these are in the API doc), They are like the magic in that instead of returning the LOG and LST to you in a dictionary (as submit does), instead the submitLOG just displays the LOG and the submitLST displays the LST (results). submitLST also has a method= paramter to allow you to have it display the log if there is no LST, or to display both in either order you like. The default is the LST whether there is any or not.
So, sas.submitLST("sas code", method='listorlog') is basically the same as the magic. If there output it's display that directly. If there's no output, the LOG is displayed instead.
Either of these last two things will get you a work around the issue with not being able use the magic with your self implemented credentials, but I would suggest using the supported method instead, and not having any of these issues to begin with.
Tom
Thank you for the reply. I created a file called _authinfo in my home directory.
The file simply looks like this.
sasfusionint user cflach password xxxxxxxxxx
However, I'm still getting prompted. Sorry that I'm not grasping this yet. Do you know what I'm doing wrong?
Perfect, now add
'authkey' : 'sasfusionint',
to your configuration definition that you are using your sascfg_personal.py file, and saspy will get those credentials for you.
Also, can you switch your accepted answer from the post you have it (implement this yourself), to one that shows to use the supported way? Just to that other users that might read this aren't sent down the wrong path?
Thanks!
Tom
Oh, and just to head off the next thing; and again, for others who might search and find this. As you said, _authinfo, I take it you're on windows. Many users on windows had default settings, where windows won't show you the file extensions in it's UIs. This also causes a problem when creating files via it's UI's, so you may have ended up not with a file called '_authinfo', but rather '_authinfo.txt' and in the file explorer it still shows it without the extension, so it looks to the user like it's named right, which it's not.
If you add the 'authkey' to your definition, and then get an error from saspy that it can't filnd that authkey, or the authinfo file (Can't remember the exact error you would get, but it won't work), then that's because the filename is wrong and you have to go remove the '.txt' from it so it's named right.
Hopefully you don't have that problem, but I've seen it plenty of times, so I wanted to write it down here, so it's apparent to anyone who reads this in the future trying to address the same issue.
Thanks again!
Tom
The configuration definition is in your sascfg_personal.py file. It's the dictionary that tells saspy where SAS is and how to connect to it. You must have configured this to be able to make a connection to start with, via : sas= saspy.SASsession()
https://sassoftware.github.io/saspy/install.html#sascfg-personal-py-details
I don't know what you'rs looks like but it would be something like the following ('authkey' : name is another key value pair):
# Windows client and Windows IOM server winiomwin = {'java' : 'java', 'iomhost' : 'windows.iom.host', 'iomport' : 8591, 'encoding' : 'windows-1252', 'classpath' : cpW }
the picture in your first post showed that you have 3 configuration definition in your config file:
sasgriddev, sasfusionhpa, sasfusionint
And you were using the one named sasfusionint.
Yes, in the instructions posted previously, you can see that you you can specify the configuration name on the SASsession invocation:
sas = saspy.SASsession(cfgname='sasfusionint')
Or, if you only using one anyway, then only specify that name in the configuration file (SAS_config_names) and saspy will just use it without any input from you:
SAS_config_names = ['sasfusionint']
and with that:
sas = saspy.SASsession()
Glad it's now getting the credentials.
Tom
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.