BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Mada1
Fluorite | Level 6

Hello,

 

Current configuration:

SAS Viya version: 3.5

SAS Viya is installed on Linux

Python version 3.7.9

Python SWAT version 1.9.0

 

Supposing that we have two libraries defined in SAS VIYA, one CAS and one not CAS.

Would anybody know if is possible to upload a table from the non CAS library to the CAS library by using Python SWAT?

 

The equivalent process in SAS Studio would be:

proc casutil;
     load data=NON_CAS_LIB.tablename outcaslib="CAS_LIB"
     casout="targetTableName";
run; 

 

Can this be done in SWAT?

After creating the SWAT connection I have tried using load_path like below but it didn't work.

 

test=conn.load_path('NON_CAS_LIB/Table_A', caslib='CAS_LIB')

 

Thank you,

Madalin

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
neal_vaidya
SAS Employee

Hey Madalin,

 

Unfortunately, there's no simple way to access a table in a non-CAS library through swat. This is because swat only communicates with the CAS server, rather than the SAS Compute Service where SAS libraries are defined and SAS code is processed. CAS doesn't know anything about the libraries in SAS, and so unfortunately swat doesn't either.

 

Luckily, there are a couple of alternatives and workarounds!

  1. Define a caslib that points to the same place — if the data source that your SAS library points to is accessible from the CAS server (for example a shared drive, or a database that you have credentials for), you can connect directly to it from CAS, rather than having to move the data through the SAS client.
  2. Create a SAS Job — if you anticipate this being a script you'll have to run regularly, you can create a job in SAS Studio that includes the SAS code you posted above. Creating a job will generate a url that you can submit HTTP requests to in order to kick off a predefined SAS program. You could also take advantage of url parameters for your SAS Job to modify the table and/or library on each HTTP call.
  3. Use SASPy — while the swat package for python can only communicate with the CAS Server, there is a different package available for communicating with a SAS process! SASPy offers a similar kind of interface to SAS from Python that swat does to CAS. The process for configuring a connection to your SAS server with SASPy is a little bit different from swat, and you can find the details here. Once you've defined your connection, you can use the
    SASPy.SASsession.sd2df('table', 'non_cas_libref')
    method to download the data into python, and upload it to CAS with swat. You can also use the 
    SASPy.SASsession.submit('code')
    method to directly submit SAS code, like the snippet you posted above, to be executed.

View solution in original post

1 REPLY 1
neal_vaidya
SAS Employee

Hey Madalin,

 

Unfortunately, there's no simple way to access a table in a non-CAS library through swat. This is because swat only communicates with the CAS server, rather than the SAS Compute Service where SAS libraries are defined and SAS code is processed. CAS doesn't know anything about the libraries in SAS, and so unfortunately swat doesn't either.

 

Luckily, there are a couple of alternatives and workarounds!

  1. Define a caslib that points to the same place — if the data source that your SAS library points to is accessible from the CAS server (for example a shared drive, or a database that you have credentials for), you can connect directly to it from CAS, rather than having to move the data through the SAS client.
  2. Create a SAS Job — if you anticipate this being a script you'll have to run regularly, you can create a job in SAS Studio that includes the SAS code you posted above. Creating a job will generate a url that you can submit HTTP requests to in order to kick off a predefined SAS program. You could also take advantage of url parameters for your SAS Job to modify the table and/or library on each HTTP call.
  3. Use SASPy — while the swat package for python can only communicate with the CAS Server, there is a different package available for communicating with a SAS process! SASPy offers a similar kind of interface to SAS from Python that swat does to CAS. The process for configuring a connection to your SAS server with SASPy is a little bit different from swat, and you can find the details here. Once you've defined your connection, you can use the
    SASPy.SASsession.sd2df('table', 'non_cas_libref')
    method to download the data into python, and upload it to CAS with swat. You can also use the 
    SASPy.SASsession.submit('code')
    method to directly submit SAS code, like the snippet you posted above, to be executed.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1033 views
  • 2 likes
  • 2 in conversation