DATA Step, Macro, Functions and more

Automate Importing multiple files

Reply
N/A
Posts: 1

Automate Importing multiple files

Hi All,

I have to import numerous files into SAS on multiple times during the month. I would really like to automate this process, but to date have failed to do so. I have to work in a SAS EG 5.1 server environment, which it seems just gives dead-ends with everything I try. The code that I have at the moment follows below. Everything seels to work fine until I try to do the actual import. I have tried importing without using macros, which works fine, but that doesn't solve my problem The macro variable datafile="&FolderPath/&&File&i" resolves to the right values, but when I run the macro, I get the following error (I have tried using PIPE to import the files, but that also doesn't seem to work in the server environment):

Error

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, /sasdata/prototype/card_markerting_analytics/mart/ABMH684/CAMPAIGN

LEADS/PCUBED/Camp46_Apr2015/absa_cc_camp46_targetfile_ntf_absa_nvsc.txt.

ERROR: Import unsuccessful.  See SAS Log for details.

SAS Code

Data List_files;
rc=FILENAME('FMyRep',"&FolderPath");
did=DOPEN('FMyRep');
memcnt=DNUM(did);

DO i=1 TO memcnt;
  filevar=LOWCASE(DREAD(did,i));

  IF LOWCASE(SCAN(filevar,-1,".")) EQ LOWCASE("&extension") THEN
   OUTPUT;
END;

rc=DCLOSE(did);
rc=FILENAME('FMyRep');
KEEP filevar;
RUN;

DATA test;
set List_files;
where index(filevar,'absa_cc');
Count +1;
call symputx('File'||left(put(Count , 3.)), filevar, 'l' );
call symputx('Count', Count , 'l' );
run;

%put _user_;

proc sql;
select count(*) into: numfiles
from test;
quit;

%macro import();
%do i = 1 %to &numfiles;


proc import
  datafile="&FolderPath/&&File&i"
  out=_i
  replace
  dbms=dlm;
  delimiter='|';
run;
%end;
%mend;
%import();

Any help solving this will be greatly appreciated!

Super User
Posts: 17,750

Re: Automate Importing multiple files

Do all the files have the same format? Is it okay if they are imported to the same dataset?

In your current code the _i that should be what? It isn't a macro variable, but should be? You use i, not _i in your loop though.
Super User
Posts: 3,101

Re: Automate Importing multiple files

The most likely cause of your error is that the directory and file you are trying to import is not accessible from your SAS server.

 

Where is /sasdata/prototype etc located? Is it on your SAS server or not? If you are not sure about this ask your SAS administrator.

 

BTW you can ignore the NOTE: Unable to open etc. That is a consequence of your SASUSER library being set to read-only, which is the default setup for SAS 9.4. 

Ask a Question
Discussion stats
  • 2 replies
  • 223 views
  • 0 likes
  • 3 in conversation