DATA Step, Macro, Functions and more

Import multiple .xlsx files WITHOUT using "pipe"

Reply
Contributor
Posts: 39

Import multiple .xlsx files WITHOUT using "pipe"

[ Edited ]

I had to switch servers I was using at work, and the new one "doesn't have SAS/CONNECT spawner running on it" per our SAS administrator.  so now i cannot use an old code that had "pipe" in it to import a whole bunch of excel files in one swoop.  they don't have to be appended, but i would like each one saved as it's own dataset.  is there anyway to do this WITHOUT using "pipe"?  everything i've looked for online doesn't have the output i want as an option.  i'm using SAS EG 6.1 (64 bit)

 

old code below

 

 

 

filename indata pipe 'dir C:\Users\engacr\Documents\"My SAS Files"\9.4\200k_Cars\2015_Q1 /b ';
data file_list; length fname $90 in_name out_name $50; infile indata truncover; input fname $ 90.; in_name=translate(scan(fname,1,'.'),'_','-'); out_name=cats('TEMP_',in_name); if upcase(scan(fname,-1,'.'))='XLSX'; run;
data _null_; set file_list end=last; call symputx(cats('dsn',_n_),in_name); call symputx(cats('outdsn',_n_),out_name); if last then call symputx('n',_n_); run; %macro test; %do i=1 %to &n; PROC IMPORT OUT= work.&&outdsn&i. DATAFILE= "C:\Users\engacr\Documents\My SAS Files\9.4\200k_Cars\2015_Q1\&&dsn&i...xlsx" DBMS=EXCEL REPLACE; GETNAMES=YES; MIXED=YES; SCANTEXT=YES; USEDATE=YES; SCANTIME=YES; DBDSOPTS= "DBTYPE=(pct_load='NUM(8)')"; RUN; %end; %mend; %test data work.combined; length veh_type_um $20.; set TEMP_:; run;

 

excel files in folder:

 

DTTX_342349.xlsx

DTTX_389923.xlsx

TTAX_346722.xlsx

TTPX_981123.xlsx

 

and so forth

 

would like them to output as:

 

DTTX_342349.sas7bdat

DTTX_389923.sas7bdat

TTAX_346722.sas7bdat

TTPX_981123.sas7bdat

 

and can append them if necessary

Super User
Posts: 19,822

Re: Import multiple .xlsx files WITHOUT using "pipe"

Posted in reply to laneylaners

So the pipe command is used to create the list of files that are to be imported.  If you don't have pipe you'll have to find another way. 

It seems that you can use filename functions for this, but I can't find a good reference. 

 

Here's one example:

 

https://communities.sas.com/t5/SAS-Procedures/Get-directory-listing-on-linux/m-p/209520/highlight/tr...

 

 

Super User
Posts: 7,809

Re: Import multiple .xlsx files WITHOUT using "pipe"

Posted in reply to laneylaners

Filename pipe is not a feature of CONNECT, it is in base SAS.

If you are using a workspace server, XCMD needs to be enabled in the server definition in the metadata.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 39

Re: Import multiple .xlsx files WITHOUT using "pipe"

Posted in reply to KurtBremser

I'm using SAS EG 6.1 (64 bit)

Super User
Posts: 7,809

Re: Import multiple .xlsx files WITHOUT using "pipe"

Posted in reply to laneylaners

laneylaners wrote:

I'm using SAS EG 6.1 (64 bit)


Which is not really important in this context. Location and definition of the workspace server is important.

Have you already tried to run your code, and what were the results (log) if you did?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 4 replies
  • 280 views
  • 2 likes
  • 3 in conversation