sassoftware / saspy

A Python interface module to the SAS System. It works with Linux, Windows, and Mainframe SAS as well as with SAS in Viya.
https://sassoftware.github.io/saspy
Other
366 stars 149 forks source link

Is there a way to load a sas7bdat file from a local pc to as Server having SAS instance? #547

Closed sourabh2404 closed 1 year ago

sourabh2404 commented 1 year ago

Hi,

I have a sas7bdat file in my local system. I have tried the following code:-

with SAS7BDAT('abc.sas7bdat') as file:

df = file.to_data_frame()

sas = saspy.SASsession(**iomj)

sas_df = sas.df2sd(df, 'TEST_WRITE', 'MYLIB')

but using this the format of data changes when I check it in the TEST_WRITE table in the SAS server. Is there a way to load this local file (abc.sas7bdat) to a SAS instance on a different server?

tomweber-sas commented 1 year ago

Without seeing what you are getting from that SAS7BDAT method (that's not a SAS provided package), I'm not sure what you're getting. But, with SASPy, and it seems you have a connection to your remote server with it, you could just do the following and have SAS access the file correctly for you (if I understand right):

sas = saspy.SASsession(**iomj)

sas.upload('abc.sas7bdat', sas.workpath)

sas_ds = sas.sasdata('abc', 'work')   # now sas_ds is your SASData object and you can do whatever you want with it

sas_ds.head()                         # or whatever you want
df = sas_ds.to_df()                   # now it's a dataframe back in your python session

Is that what you're looking for?

Tom

sourabh2404 commented 1 year ago

This is great, I was looking for something like this. Thank you