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!
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;
@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;
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;
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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.