I am trying to read SQL query output and create a SAS dataset using Python pandas. My SQL query is executing properly but only importing column names into SAS dataset due to data shifting. It is an encoding issue and I wanted some guidance on how to fix this. Below is my code:
with open ('Query.sql', mode = 'r', encoding='utf-8-sig') as sql_input:
sql_input = sql_input.read()
My_string = str('mssql+pyodbc://USER:Pass' + server + '/' + database + '?driver=SQL+Server+Native+Client+11.0')
engine = My_engine(My_string)
df = pd.read_sql_query(sql_input,engine)
Viya = saspy.SASsession(omruser='User', omrpw='PWD', cfgfile='cfgfile.py')
Viya.submit('libname lib "path";')
Viya.df2sd(df=df3, table='Test', libref='lib')
and then I create SAS Viya Session and submit with the path and dataset name. When I check SAS dataset, I see only columns created.
Error : INPUT statement exceeded record length. INFILE CARDS OPTION STOPOVER specified.
Any suggestions?
ds2df()
works? Is it generating SAS code? – Tomdf2sd
(alias fordataframe2sasdata
) streams data to python using datalines, which can be ... interesting ... in some cases, and apparently this is one of them. I understand why the developer chose that, but also find it causes some issues, like this. – Joe