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
373 stars 150 forks source link

read CSV data #359

Closed ghost closed 3 years ago

ghost commented 3 years ago

I am just wondering if there is any direct way to read CSV file without using pandas library (I mean the SAS way to import file). Can't we use sas.read_csv( ) instead of combination of pd.read_csv( ) and then sas.df2sd( )? Last question - Is there any way to create permanent library?

import pandas as pd
pandasdf = pd.read_csv("/content/sample_data/california_housing_train.csv")
sasdf = sas.df2sd(pandasdf, 'sasdf')
sas.submitLST("proc print data=work.sasdf (obs=5);run;", method='listorlog')
tomweber-sas commented 3 years ago

Yes, you can use sas.read_csv() is the file is accessible to SAS. And just fyi, after you created sasdf in the code you have (which sound like sas data frame, but that is a SASdata object), you could have just done: sdsdf.head() instead of the submitLST with proc print, as that's already what head() does for you.

You can assign a library using the sas.saslib() method. It's just the python method version of submitting your own libname statement via submit.