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

I am using  SAS University edition .

I have placed the 2 CSV files with different name in the same "my folder" and I want it to be imported to sas. I am trying to create macros for importing multiple csv or xls files . 

 

my location of the file is "/folders/myshortcuts/myfolder/DS1" 

 

Please suggest as to which part of the code is wrong ?

 

I have tried the below code but I am getting the error . 

Code 

%macro drive(dir,ext);
%local cnt filrf rc did memcnt name;
%let cnt=0;

%let filrf=mydir;
%let rc=%sysfunc(filename(filrf,&dir));
%let did=%sysfunc(dopen(&filrf));
%if &did ne 0 %then %do;
%let memcnt=%sysfunc(dnum(&did));

%do i=1 %to &memcnt;

%let name=%qscan(%qsysfunc(dread(&did,&i)),-1,.);

%if %qupcase(%qsysfunc(dread(&did,&i))) ne %qupcase(&name) %then %do;
%if %superq(ext) = %superq(name) %then %do;
%let cnt=%eval(&cnt+1);
%put %qsysfunc(dread(&did,&i));
proc import datafile="&dir\%qsysfunc(dread(&did,&i))" out=dsn&cnt
dbms=csv replace;
run;
%end;
%end;

%end;
%end;
%else %put &dir cannot be open.;
%let rc=%sysfunc(dclose(&did));

%mend drive;

%drive(/folders/myshortcuts/myfolder/DS1,csv)

 

Error in LOG 

 

 
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 %macro drive(dir,ext);
74 %local cnt filrf rc did memcnt name;
75 %let cnt=0;
76
77 %let filrf=mydir;
78 %let rc=%sysfunc(filename(filrf,&dir));
79 %let did=%sysfunc(dopen(&filrf));
80 %if &did ne 0 %then %do;
81 %let memcnt=%sysfunc(dnum(&did));
82
83 %do i=1 %to &memcnt;
84
85 %let name=%qscan(%qsysfunc(dread(&did,&i)),-1,.);
86
87 %if %qupcase(%qsysfunc(dread(&did,&i))) ne %qupcase(&name) %then %do;
88 %if %superq(ext) = %superq(name) %then %do;
89 %let cnt=%eval(&cnt+1);
90 %put %qsysfunc(dread(&did,&i));
91 proc import datafile="&dir\%qsysfunc(dread(&did,&i))" out=dsn&cnt
92 dbms=csv replace;
93 run;
94 %end;
95 %end;
96
97 %end;
98 %end;
99 %else %put &dir cannot be open.;
100 %let rc=%sysfunc(dclose(&did));
101
102 %mend drive;
103
104 %drive(/folders/myshortcuts/myfolder/DS1,csv)
H1b mod.csv
 
NOTE: Unable to open parameter catalog: SASUSER.PARMS.PARMS.SLIST in update mode. Temporary parameter values will be saved to
WORK.PARMS.PARMS.SLIST.
ERROR: Physical file does not exist, /folders/myshortcuts/myfolder/DS1\H1b mod.csv.
ERROR: Import unsuccessful. See SAS Log for details.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IMPORT used (Total process time):
real time 0.89 seconds
cpu time 0.23 seconds
 
h1b_kaggle.csv
 
 
 
NOTE: Unable to open parameter catalog: SASUSER.PARMS.PARMS.SLIST in update mode. Temporary parameter values will be saved to
WORK.PARMS.PARMS.SLIST.
ERROR: Physical file does not exist, /folders/myshortcuts/myfolder/DS1\h1b_kaggle.csv.
ERROR: Import unsuccessful. See SAS Log for details.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IMPORT used (Total process time):
real time 0.07 seconds
cpu time 0.06 seconds
 
105
106 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
119
 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SuzanneDorinski
Lapis Lazuli | Level 10

Change the PROC IMPORT line to use &dir/%qsysfunc, instead of &dir\%qsysfunc.

 

 

proc import datafile="&dir/%qsysfunc(dread(&did,&i))" out=dsn&cnt

 

View solution in original post

3 REPLIES 3
SuzanneDorinski
Lapis Lazuli | Level 10

Change the PROC IMPORT line to use &dir/%qsysfunc, instead of &dir\%qsysfunc.

 

 

proc import datafile="&dir/%qsysfunc(dread(&did,&i))" out=dsn&cnt

 

vjjags
Calcite | Level 5
Thanks Suzanne for your immediate reply now it works perfectly ..

vjjags
Calcite | Level 5

thanks for your prompt reply it works perfectly

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 1276 views
  • 1 like
  • 2 in conversation