-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error with saspy.read_csv() when passing an URL for a filename #634
Comments
Hey, that looks like a parsing issue on the SAS side. It seems to be thinking there are macros and such embedded in there or something. I'll have to see what you are actually submitting and the log with all the output so I can see what's really going on. Can you submit the same code as SASPy is generating in a stand alone session in a way that works with no errors from SAS? |
Well, you mentioned double quotes in your comment, so I just tried a simple case with single vs double quotes. I see with single it doesn't complain and w/ double it tries to resolve embedded macros. We are so inconsistent sometimes w/ parsing and quoting an macro language; drives me nuts.
|
As this does seem to be an issue w/ double vs. sincgle quotes, I've pushed the change to generate the path w/ single quotes and see it behave better. Can you pull from main and test it out with your scenario? It seems to resolve the issue from what I can tell with my test cases. Needs to work for you too though. You can pull from main via
|
Thanks Tom.
I believe your updated code resolved the filename (double quote) issue and able to successfully create a SAS dataset. Below are the details using the repo…
import saspy
sas=saspy.SASsession()
link = 'https://mrlxxxxxxxxxxxxxxxxx&X-Amz-xxxxxxxxxxxxxx'
sascsv = sas.read_csv(link, table='csvdata', libref='work')
print(sas.saslog())
22 filename _x url
22 ! 'https://mrlxxxxxxxxxxxxxxxxxxxxxx';
NOTE: The quoted string currently being processed has become more than 262 bytes long. You might have unbalanced quotation marks.
23 proc import datafile=_x out=work.'csvdata'n dbms=csv replace; run;filename _x clear;
NOTE: Unable to open parameter catalog: SASUSER.PARMS.PARMS.SLIST in update mode. Temporary parameter values will be saved to
WORK.PARMS.PARMS.SLIST.
NOTE: Unable to open SASUSER.PROFILE. WORK.PROFILE will be opened instead.
NOTE: All profile changes will be lost at the end of the session.
24 /**********************************************************************
25 * PRODUCT: SAS
26 * VERSION: V.04.00
27 * CREATOR: External File Interface
28 * DATE: 24FEB25
29 * DESC: Generated SAS Datastep Code
30 * TEMPLATE SOURCE: (None Specified.)
31 ***********************************************************************/
32 data WORK.csvdata ;
33 %let _EFIERR_ = 0; /* set the ERROR detection macro variable */
34 infile _X delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;
35 informat pk best32. ;
36 informat unmasked_col1 $1. ;
37 informat masked_col2 $1. ;
38 informat new_col1 $5. ;
39 format pk best12. ;
40 format unmasked_col1 $1. ;
41 format masked_col2 $1. ;
42 format new_col1 $5. ;
43 input
44 pk
45 unmasked_col1 $
46 masked_col2 $
47 new_col1 $
48 ;
49 if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable */
50 run;
NOTE: The infile _X is:
Filename=https://mrlxxxxxxxxxxxxxxxxxx,
Local Host Name=run-67bca7d7ef61b605d4f00353-d55db,
Local Host IP addr=xxxxxxxxxxxxxxxxx,
Service Hostname Name=xxxxxxxxxxxxxx,
Service IP addr=xxxxxxxxxxx,
Service Name=N/A,Service Portno=xxx,
Lrecl=32767,Recfm=Variable
NOTE: 3 records were read from the infile _X.
The minimum record length was 11.
The maximum record length was 11.
NOTE: The data set WORK.CSVDATA has 3 observations and 4 variables.
NOTE: DATA statement used (Total process time):
real time 0.08 seconds
cpu time 0.01 seconds
3 rows created in WORK.csvdata from _X.
NOTE: WORK.CSVDATA data set was successfully created.
NOTE: The data set WORK.CSVDATA has 3 observations and 4 variables.
NOTE: PROCEDURE IMPORT used (Total process time):
real time 0.42 seconds
cpu time 0.06 seconds
NOTE: Fileref _X has been deassigned.
From: Tom Weber ***@***.***>
Sent: Monday, February 24, 2025 10:32 AM
To: sassoftware/saspy ***@***.***>
Cc: Talanayar, Murali ***@***.***>; Author ***@***.***>
Subject: Re: [sassoftware/saspy] Error with saspy.read_csv() when passing an URL for a filename (Issue #634)
EXTERNAL EMAIL– Use caution with any links or file attachments.
As this does seem to be an issue w/ double vs. sincgle quotes, I've pushed the change to generate the path w/ single quotes and see it behave better. Can you pull from main and test it out with your scenario? It seems to resolve the issue from what I can tell with my test cases. Needs to work for you too though. You can pull from main via
pip install ***@***.******@***.***
or since main is the default branch, you don't need @main<https://github.com/main>:
pip install ***@***.***/sassoftware/saspy.git
>> sd = sas.read_csv("http://xxx&booxxx%32xxxx")
/opt/tom/github/saspy/saspy/sasiostdio.py:1118: UserWarning: Noticed 'ERROR:' in LOG, you ought to take a look and see if there was a problem
warnings.warn("Noticed 'ERROR:' in LOG, you ought to take a look and see if there was a problem")
>> print(sas.lastlog())
21 ;*';*";*/;
22 filename _x url 'http://xxx&booxxx%32xxxx';
23 proc import datafile=_x out='_csv'n dbms=csv replace; run;filename _x clear;
NOTE: Unable to connect to host xxx&booxxx%32xxxx. Check validity of host name.
ERROR: Physical file does not exist, http://xxx&booxxx%32xxxx.
ERROR: Import unsuccessful. See SAS <%20unsuccessful.%20%20See%20SAS%20> Log for details.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IMPORT used (Total process time):
real time 2.82 seconds
cpu time 0.36 seconds
NOTE: Fileref _X has been deassigned.
24
25
26 ;*';*";*/;%put %upcase(e3969440a681a2408885998500000004);
E3969440A681A2408885998500000004
27 ;*';*";*/;
28 data _null_; e = exist("'_csv'n");
29 v = exist("'_csv'n", 'VIEW');
30 if e or v then e = 1;
31 put 'TABLE_EXISTS=' e 'TAB_EXTEND=';run;
TABLE_EXISTS=0 TAB_EXTEND=
NOTE: DATA statement used (Total process time):
real time 0.06 seconds
cpu time 0.02 seconds
32
33 ;*';*";*/;%put %upcase(e3969440a681a2408885998500000005);
E3969440A681A2408885998500000005
>> sas.submitLOG('''filename _x url 'http://xxx&booxxx%32xxxx';''')
34 ods listing close;ods html5 (id=saspy_internal) file=stdout options(bitmap_mode='inline') device=svg style=HTMLBlue; ods
34 ! graphics on / outputfmt=png;
NOTE: Writing HTML5(SASPY_INTERNAL) Body file: STDOUT
35
36 filename _x url 'http://xxx&booxxx%32xxxx';
37
38 ods html5 (id=saspy_internal) close;ods listing;
>> sas.submitLOG('''filename _x url "http://xxx&booxxx%32xxxx";''')
40 ods listing close;ods html<s%20listing%20close;ods%20html>5 (id=saspy_internal) file=stdout options(bitmap_mode='inline') device=svg style=HTMLBlue; ods
40 ! graphics on / outputfmt=png;
NOTE: Writing HTML5(SASPY_INTERNAL) Body file: STDOUT
41
42 filename _x url "http://xxx&booxxx%32xxxx";
WARNING: Apparent symbolic reference<arent%20symbolic%20reference> BOOXXX not resolved.
43
44 ods html5 (id=saspy_internal) close;ods listing;
>>
—
Reply to this email directly, view it on GitHub<#634 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/BEOWN3T7U3IOIQV725JG7B32RM3ORAVCNFSM6AAAAABXVKNBACVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNZYHAYTMOJVG4>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
[tomweber-sas]tomweber-sas left a comment (sassoftware/saspy#634)<#634 (comment)>
As this does seem to be an issue w/ double vs. sincgle quotes, I've pushed the change to generate the path w/ single quotes and see it behave better. Can you pull from main and test it out with your scenario? It seems to resolve the issue from what I can tell with my test cases. Needs to work for you too though. You can pull from main via
pip install ***@***.******@***.***
or since main is the default branch, you don't need @main<https://github.com/main>:
pip install ***@***.***/sassoftware/saspy.git
>> sd = sas.read_csv("http://xxx&booxxx%32xxxx")
/opt/tom/github/saspy/saspy/sasiostdio.py:1118: UserWarning: Noticed 'ERROR:' in LOG, you ought to take a look and see if there was a problem
warnings.warn("Noticed 'ERROR:' in LOG, you ought to take a look and see if there was a problem")
>> print(sas.lastlog())
21 ;*';*";*/;
22 filename _x url 'http://xxx&booxxx%32xxxx';
23 proc import datafile=_x out='_csv'n dbms=csv replace; run;filename _x clear;
NOTE: Unable to connect to host xxx&booxxx%32xxxx. Check validity of host name.
ERROR: Physical file does not exist, http://xxx&booxxx%32xxxx.
ERROR: Import unsuccessful. See SAS <%20unsuccessful.%20%20See%20SAS%20> Log for details.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IMPORT used (Total process time):
real time 2.82 seconds
cpu time 0.36 seconds
NOTE: Fileref _X has been deassigned.
24
25
26 ;*';*";*/;%put %upcase(e3969440a681a2408885998500000004);
E3969440A681A2408885998500000004
27 ;*';*";*/;
28 data _null_; e = exist("'_csv'n");
29 v = exist("'_csv'n", 'VIEW');
30 if e or v then e = 1;
31 put 'TABLE_EXISTS=' e 'TAB_EXTEND=';run;
TABLE_EXISTS=0 TAB_EXTEND=
NOTE: DATA statement used (Total process time):
real time 0.06 seconds
cpu time 0.02 seconds
32
33 ;*';*";*/;%put %upcase(e3969440a681a2408885998500000005);
E3969440A681A2408885998500000005
>> sas.submitLOG('''filename _x url 'http://xxx&booxxx%32xxxx';''')
34 ods listing close;ods html5 (id=saspy_internal) file=stdout options(bitmap_mode='inline') device=svg style=HTMLBlue; ods
34 ! graphics on / outputfmt=png;
NOTE: Writing HTML5(SASPY_INTERNAL) Body file: STDOUT
35
36 filename _x url 'http://xxx&booxxx%32xxxx';
37
38 ods html5 (id=saspy_internal) close;ods listing;
>> sas.submitLOG('''filename _x url "http://xxx&booxxx%32xxxx";''')
40 ods listing close;ods html<s%20listing%20close;ods%20html>5 (id=saspy_internal) file=stdout options(bitmap_mode='inline') device=svg style=HTMLBlue; ods
40 ! graphics on / outputfmt=png;
NOTE: Writing HTML5(SASPY_INTERNAL) Body file: STDOUT
41
42 filename _x url "http://xxx&booxxx%32xxxx";
WARNING: Apparent symbolic reference<arent%20symbolic%20reference> BOOXXX not resolved.
43
44 ods html5 (id=saspy_internal) close;ods listing;
>>
—
Reply to this email directly, view it on GitHub<#634 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/BEOWN3T7U3IOIQV725JG7B32RM3ORAVCNFSM6AAAAABXVKNBACVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNZYHAYTMOJVG4>.
You are receiving this because you authored the thread.Message ID: ***@***.***>***@***.***%3e>
This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (126 East Lincoln Ave., P.O. Box 2000, Rahway, NJ USA 07065) and/or its affiliates, that may be confidential, proprietary copyrighted and/or legally privileged. (Direct contact information for affiliates is available at - Contact us - MSD<https://www.msd.com/contact-us/>.) It is intended solely for the use of the individual or entity named on this message. If you are not the intended recipient, and have received this message in error, please notify us immediately by reply e-mail and then delete it from your system.
|
That great! Thanks for trying it out so quickly. I see I have the same issue in write_csv, but everywhere else in saspy that I generate the filename statement I use single quotes. So, I fixed it for write_csv also. I have one other change at main for an internal use that has a strange issue. Once I decide if I want that change in or not, I'll build a new release with this for for you. I'll keep this open till I do that, then I expect it can be closed once that done? |
Sure Tom - that should be fine. for now we are proceeding with the submit option. thanks. sas.symput('csvlink', link) sas.submitLOG( |
Yep, that's the other workaround where you take advantage of it parsing the macro from the string!
I'll try to get this fix for you into a new release this week so you don't have to do either of these :) |
Describe the bug
I am trying to import a CSV file which is an URL link using read_csv() to create a SAS dataset. There are few errors reported in the log and may be primary one is from the filename statement which has the URL enclosed in double quotes causing "&" to be resolved.
To Reproduce
Details below:
filename _x url 22 ! "https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
The URL string has few % and & - here is one piece of URL "GKl9eqTlImvzYS66LqIewbx9wmm6qnkigD1BQP7YkpescyTnLjd0%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20250222T200156Z&X-Amz-Sign"
NOTE: The quoted string currently being processed has become more than 262 bytes long. You might have unbalanced quotation marks. WARNING: Apparent symbolic reference X not resolved. WARNING: Apparent symbolic reference X not resolved. WARNING: Apparent symbolic reference X not resolved. WARNING: Apparent symbolic reference X not resolved. WARNING: Apparent symbolic reference X not resolved. WARNING: Apparent symbolic reference X not resolved. WARNING: Apparent symbolic reference X not resolved. 23 proc import datafile=_x out='ae_aim'n dbms=csv replace; getnames=YES; run;filename _x clear;
Appreciate any help!
The text was updated successfully, but these errors were encountered: