BookmarkSubscribeRSS Feed
paulochen
Calcite | Level 5

Hi,

 

I'm testing the Saspy here, but in order to connect to a dataset from SAS I need to provide a password, since this is a protected dataset.

 

DATA dataset;

SET database.table (PW='****')

RUN;

 

How can I provide this password in saspy, is there any method for this?

3 REPLIES 3
ChrisHemedinger
Community Manager

I don't see a pw= or related options on the sasdata object in SASPy right now, but @sastpw might have some ideas. You can also submit an issue/request at the GitHub project.

Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!
sastpw
SAS Employee

Hey! Providing data sets passwords is accomplished through data set options. SASPy provides an attribute on the SASdata object for this; dsopts. Although pw= (read,write,alter=) aren’t listed in the doc as examples, any keyword=value data set option will work in that. In this case, I would suggest using encoded passwords so that they don’t show up in the log. Here’s an example of this. Oh, and with the encoded pw, provide wrapping quotes with it so there’s no syntax error from SAS.

# create a dataset w/ passwords:
>>> sas.submitLOG('data a(pw='tom');x=1;run;')

24   data a(pw=XXXXX);x=1;run;
NOTE: The data set USER.A has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.24 seconds
      cpu time            0.03 seconds


#Assign the SASData object  (without the data set options, yet):
>>> sd = sas.sasdata('a')
>>> sd
Libref  = USER
Table   = a
Dsopts  = {}
Results = Pandas

# See that this will fail when trying to access the data.
>>> sd.contents('text')
/opt/tom/github/saspy/saspy/sasiostdio.py:1045: UserWarning: Noticed 'ERROR:' in LOG, you ought to take a look and see if there was a problem
  warnings.warn("Noticed 'ERROR:' in LOG, you ought to take a look and see if there was a problem")

# see error in log after (I removed some of the output to make it more readable)
>>> print(sas.lastlog())
50   proc contents data=USER.'a'n ;run;
ERROR: Invalid or missing READ password on member USER.A.DATA.
NOTE: Statements not processed because of errors noted above.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE CONTENTS used (Total process time):
      real time           0.04 seconds
      cpu time            0.00 seconds

# Now, add the data set option to the SASData object and see it will work
>>> sd.dsopts = {'read':'tom'}
>>> sd
Libref  = USER
Table   = a
Dsopts  = {'read': 'tom'}
Results = Pandas

>>> sd.contents('text')
                                                           The SAS System                         09:10 Monday, October 31, 2022   1

                                                       The CONTENTS Procedure

               Data Set Name        USER.A                                                   Observations          1
               Member Type          DATA                                                     Variables             1
               Engine               V9                                                       Indexes               0
               Created              10/31/2022 09:11:25                                      Observation Length    8
               Last Modified        10/31/2022 09:11:25                                      Deleted Observations  0
               Protection           READ/WRITE/ALTER                                         Compressed            NO
               Data Set Type                                                                 Sorted                NO
               Label
               Data Representation  SOLARIS_X86_64, LINUX_X86_64, ALPHA_TRU64, LINUX_IA64
               Encoding             latin1  Western (ISO)


                                                 Engine/Host Dependent Information

                              Data Set Page Size          65536
                              Number of Data Set Pages    1
                              First Data Page             1
                              Max Obs per Page            8061
                              Obs in First Data Page      1
                              Number of Data Set Repairs  0
                              Filename                    /opt/tom/github/saspy/saspy/user/a.sas7bdat
                              Release Created             9.0401M8
                              Host Created                Linux
                              Inode Number                327178180
                              Access Permission           rw-r--r--
                              Owner Name                  sastpw
                              File Size                   128KB
                              File Size (bytes)           131072


                                             Alphabetic List of Variables and Attributes

                                                    #    Variable    Type    Len

                                                    1    x           Num       8


# But, get the encrypted version of your password and use that instead
>>> sas.submitLOG("proc pwencode in='tom';run;")
72   proc pwencode in=XXXXX;run;

{SAS002}A984D9082E51049E

NOTE: PROCEDURE PWENCODE used (Total process time):
      real time           0.03 seconds
      cpu time            0.00 seconds


# replace the pw (you can specify pw=/read=/write=/alter=, as you need, each as it’s own option too)
# Note the embedded pair of quotes so that the value provided to SAS will be quoted, as it requires. 
>>> sd.dsopts = {'read':"'{SAS002}A984D9082E51049E'"}
>>> sd.contents('text')


                                                           The SAS System                         09:10 Monday, October 31, 2022   2

                                                       The CONTENTS Procedure

               Data Set Name        USER.A                                                   Observations          1
               Member Type          DATA                                                     Variables             1
               Engine               V9                                                       Indexes               0
               Created              10/31/2022 09:11:25                                      Observation Length    8
               Last Modified        10/31/2022 09:11:25                                      Deleted Observations  0
               Protection           READ/WRITE/ALTER                                         Compressed            NO
               Data Set Type                                                                 Sorted                NO
               Label
               Data Representation  SOLARIS_X86_64, LINUX_X86_64, ALPHA_TRU64, LINUX_IA64
               Encoding             latin1  Western (ISO)


                                                 Engine/Host Dependent Information

                              Data Set Page Size          65536
                              Number of Data Set Pages    1
                              First Data Page             1
                              Max Obs per Page            8061
                              Obs in First Data Page      1
                              Number of Data Set Repairs  0
                              Filename                    /opt/tom/github/saspy/saspy/user/a.sas7bdat
                              Release Created             9.0401M8
                              Host Created                Linux
                              Inode Number                327178180
                              Access Permission           rw-r--r--
                              Owner Name                  sastpw
                              File Size                   128KB
                              File Size (bytes)           131072


                                             Alphabetic List of Variables and Attributes

                                                    #    Variable    Type    Len

                                                    1    x           Num       8
>>> print(sas.lastlog())

296  proc contents data=USER.'a'n (read='{SAS002}A984D9082E51049E' );run;
NOTE: The PROCEDURE CONTENTS printed page 2.
NOTE: PROCEDURE CONTENTS used (Total process time):
      real time           0.03 seconds
      cpu time            0.02 seconds

sastpw
SAS Employee
Just to follow up, were you able to access your data using the dsopts to provide the password?
Thanks,
Tom

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1138 views
  • 4 likes
  • 3 in conversation