BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sun538
Obsidian | Level 7

Hello,

 

I need to read a csv file using the following code:

 

proc import datafile='\\...\Trades.csv'
out=Transactions
dbms=csv
replace;
run;

 

However, I get the error saying " ERROR: Open code statement recursion detected." The first lines of log is as below:

 

NOTE: WORK._PRODSAVAIL         data set was successfully created.
NOTE: The data set WORK._PRODSAVAIL has 8 observations and 6 variables.
NOTE: PROCEDURE  used (Total process time):
      real time           0.13 seconds
      cpu time            0.14 seconds
      
44             input
45                         "PK!!®¸yoz[C"N  $
46             ;
47             if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro variable */
48             run;
49         
50         GOPTIONS NOACCESSIBLE;
ERROR: Open code statement recursion detected.
51         %LET _CLIENTTASKLABEL=;
52         %LET _CLIENTPROCESSFLOWNAME=;
53         %LET _CLIENTPROJECTPATH=;
54         %LET _CLIENTPROJECTPATHHOST=;
55         %LET _CLIENTPROJECTNAME=;
56         %LET _SASPROGRAMFILE=;
57         %LET _SASPROGRAMFILEHOST=;
58         
59         ;*';*";*/;quit;run;
60         ODS _ALL_ CLOSE;
61         
62      
63         QUIT; RUN;
64         

Could you please let me know why that happens and how to fix it. Thank you!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

That step should run without error as long as the file exists.  Now you need to LOOK at what it shows and figure out if your file is really a CSV file or not.   Does it have a header row?  Are the values separated by commas?  Where there any notes about transcoding issues?

 

Share the log if you need more help.

 

If the file is really a CSV file there is not any need to use PROC IMPORT to read the file. Just write your own data step to read the file.  Just define your variables. Add INFORMAT or FORMAT for variables that NEED them (usually just date, time or datetime values).  Then just read all of the variables.

data want;
  infile 'myfile.csv' dsd truncover firstobs=2;
  length firstvar $20 ..... lastvar 8;
 * informat datevar date. ;
 * format datevar date9.;
  input firstvar -- lastvar;
run;

View solution in original post

8 REPLIES 8
Reeza
Super User
That looks like the error happens before you code runs. Restart your SAS Session and if the error persists I'd first check if you have any code set up to run ahead of this via an autoexec or prior code set up in the EG project. If you don't have anything like that then I'd suggest talking to tech support.
sun538
Obsidian | Level 7
Thanks @Reeza. I restarted my SAS session several times, even I opened a new SAS program just for that. Still I get the same issue. It is very unusual as I import a lot of different flat files everyday but I have not faced such error.
Reeza
Super User
It looks like the error is before you submit any code. Have you tried submitting other code? I suspect you'll get the same error.
sun538
Obsidian | Level 7
Yes, I did and the other codes work properly. I get the same error only for the mentioned- import csv file code.
Tom
Super User Tom
Super User

@sun538 wrote:
Yes, I did and the other codes work properly. I get the same error only for the mentioned- import csv file code.

Your error message makes it look like your file is either binary or using an encoding that youre session cannot handle.

 

Check if the file is actually a CSV file.  Just write a simple data step to read the first few lines and dump them to the log.

data _null_;
  infile 'myfile.csv' obs=5 ;
  input;
  list;
run;
sun538
Obsidian | Level 7
Thanks @Tom for your comment. I followed your suggestion and the code is running error-free. So, what do you think the issue is knowing that fact?
Tom
Super User Tom
Super User

That step should run without error as long as the file exists.  Now you need to LOOK at what it shows and figure out if your file is really a CSV file or not.   Does it have a header row?  Are the values separated by commas?  Where there any notes about transcoding issues?

 

Share the log if you need more help.

 

If the file is really a CSV file there is not any need to use PROC IMPORT to read the file. Just write your own data step to read the file.  Just define your variables. Add INFORMAT or FORMAT for variables that NEED them (usually just date, time or datetime values).  Then just read all of the variables.

data want;
  infile 'myfile.csv' dsd truncover firstobs=2;
  length firstvar $20 ..... lastvar 8;
 * informat datevar date. ;
 * format datevar date9.;
  input firstvar -- lastvar;
run;
ballardw
Super User

When I see something like this in the log:

  input
45                         "PK!!®¸yoz[C"N  $
46             ;

that says Proc Import thought that something like that quoted string was a column name and attempts to use it as a variable. If there are % or & also on that first line of the data then when enclosed inside the double quotes to create the name literal values then SAS might attempt to resolve them as macro variables or macro calls. Malformed macros or use of is a common cause of that recursion error.

 

However since the fragment of data step code you show references creating WORK._PRODSAVAIL and not the WORKS.TRANSACTIONS that would have been created then the log you show does not actually relate to the code you have shown.

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1159 views
  • 1 like
  • 4 in conversation