BookmarkSubscribeRSS Feed
JT1
Calcite | Level 5 JT1
Calcite | Level 5

Hello,

I installed a DLL file to facilitate the importing/exporting of any files from SAS EG to my local machine and vice versa. Specifically, I'm trying to export mutliple CSV files from a desginated SAS library to different folders on one of my local drives. I developed a macro that successfully builds each of the CSV files needed for the Export Task (I created my own task template...see attached). However, the problem I am encountering is that when I go to run the Export Task, instead of processing all the files, it processes only the last file built from the macro, thereby rendering the macro useless. Is there a way for me to export all files (in this case 4) from the library using the Export Task in one go? I appreciate any help or insight on this. Below is my macro code and I've attached a screen shot of my custom Task Template. Thank you

 

%macro csv_export (st,aco,datafile);
/* Data to export */
%let lib = TEST;
proc sql noprint;
select memname
into : datafile1 - : datafile4
from sashelp.vmember
where libname = "TEST";
quit;


/* Local folder to download to */
%let download_to = E:\AA_AU_Monthly_Runs\AA_AU 2017\AA_AU_2017_03_Mar\Step_100_Roster_Prep\&st\&aco ;

/* detect proper delim for UNIX vs. Windows */
%let delim=%sysfunc(ifc(%eval(&sysscp. = WIN),\,/));

%let download_from =
%sysfunc(getoption(work))&delim.&datafile...csv;

filename src "&download_from.";

proc export data=&lib..&datafile.
dbms=csv
file=src
replace;
run;

filename src clear;

%mend csv_export;

%csv_export(TX,ADV,&datafile1);
%csv_export(TX,ADV,&datafile2);
%csv_export(IL,LURIE,&datafile3);
%csv_export(IL,LURIE,&datafile4);

 


csv_task_template.PNG
5 REPLIES 5
hollandnumerics
Pyrite | Level 9

JT1,

 

The problems lies in the following SAS statement:

%let download_from =
%sysfunc(getoption(work))&delim.&datafile...csv;

which points to a single file, and gets overwritten by each macro call. My solution, however, depends on your CSV filenames being the only CSV files present in a &download_from folder:

%let download_from =
%sysfunc(getoption(work));
filename src "&download_from.&delim.&datafile...csv";

You should then be able to use the following text in the Source files box:

&download_from.&delim.*.csv

 Hope this makes sense...........Phil

Philip R Holland
Holland Numerics: Blog and Forums
http://blog.hollandnumerics.org.uk
JT1
Calcite | Level 5 JT1
Calcite | Level 5

Phil,

 

Thank you for your response! It certainly makes sense and I made your suggested changes. However, when I run the task, I am now receiving the following error:

 

ERROR: Target folder (&download_to.) does not exist or cannot be accessed on LOKN3DDS (this is the name of my local machine).

 

I ran it again with my old code and got the same error so I doubt it has anything to do with the modifications but puzzled as to why this error is showing up now and not prior.

 

-Jared

 

 

 

hollandnumerics
Pyrite | Level 9

Jt1,

 

I suspect you are being impacted by macro variable "scope", because, unless you have defined both &download_from and &download_to outside of the macro, it won't exist outside. Therefore I suggest you add a single statement at the top of your program outside of the macro to make sure the macro variables are available everywhere:

 

%GLOBAL download_from download_to;

 

..............Phil

Philip R Holland
Holland Numerics: Blog and Forums
http://blog.hollandnumerics.org.uk
JT1
Calcite | Level 5 JT1
Calcite | Level 5

Hollandnumerics,

 

I added in the %GLOBAL download_from download_to. However, now I am receiving a different type of error. Specifically....

 

ERROR: Download exception occurred. <?xml version="1.0" ?><Exceptions><Exception><SASMessage severity="Error">Invalid file, /SASWork/SAS_work064400005256_pwauslsasgap09/SAS_work386F00005256_pwauslsasgap09.</SASMessage></Exception></Exceptions>

 

Any ideas?

 

Thanks,

Jared

hollandnumerics
Pyrite | Level 9

Jared,

 

I can see 2 copies of the WORK folder (/SASWork/SAS_work064400005256_pwauslsasgap09) in the error message. I would look at what you are actually providing to the EG Task in &download_from and &download_to, because I don't think what you have in &download_from.&delim.*.csv is "folder/*.csv".

 

.............Phil

Philip R Holland
Holland Numerics: Blog and Forums
http://blog.hollandnumerics.org.uk

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 2158 views
  • 0 likes
  • 2 in conversation