import feather
import pandas as pd
import saspy
pd.show_versions()
sas = saspy.SASsession()
cars = sas.sasdata('cars', libref='sashelp')
print(type(cars))
SAS dataset SASHELP.CARS converted to panda dataframe car_df
car_df = cars.to_df()
print(type(car_df))
panda dataframe car_df converted to SAS dataset WORK.CARS
car_df2 = sas.df2sd(car_df, 'cars')
print(type(car_df2))
Read a dataframe from disk with the feather library created previously from a R dataframe
path = '/home/sas/notebook/r_staff.feather'
pd_staff = feather.read_dataframe(path)
pd_staff.dtypes
print(type(pd_staff))
print(pd_staff)
The dataframe pd_staff appears acceptable to Python, but is not acceptable to the sas.df2sd call
sd_staff = sas.df2sd(pd_staff, 'staff')
Copy the pd_staff dataframe with default deep=True
copy_deep_true = pd_staff.copy()
id(pd_staff)
print(type(copy_deep_true))
id(copy_deep_true)
Call the sas.df2sd method. The copied dataframe is not acceptable to this call.
cdt = sas.df2sd(copy_deep_true, 'staff_t')
Copy pd_staff operation with deep=false parameter
copy_deep_false = pd_staff.copy(deep=False)
id(pd_staff)
print(type(copy_deep_false))
id(copy_deep_false)
Call the sas.df2sd method. copy_deep_false dataframe is not acceptable.
cdf = sas.df2sd(copy_deep_false, 'staff_f')
Create the medals dataframe with the read.csv method
df_medals = pd.read_csv("http://winterolympicsmedals.com/medals.csv")
df_medals.head()
Call the sas.df2sd method to create the SAs dataset WORK.medals2
sd_medals = sas.df2sd(df_medals, 'medals2')
sd_medals.contents()
sas