Export certain datasets as csv from macro

#1
Hi

I have a functioning macro that creates a list of datasets from a master file that is unique for each day. The datasets I create in the SAS macro therefore have the data added to them so they are easy to categorize.

I would like to export some of the datasets as I create during the macro as csv files, as this will make analysis in R easier. I have written a Proc Export for each file I would like to export inside the macro itself, however even with the REPLACE function taken out, only the last file of the macro's run is saved to the file destination.

I use the below code for each dataset I would like to export while the macro is running.

Whould I write the proc export statements as individual macros instead?

Code:
PROC EXPORT DATA= dataset&year&mon2&day2

            OUTFILE= "D:\Data" 
            DBMS=CSV LABEL;
     PUTNAMES=YES;
RUN;
Thanks
 

Dason

Ambassador to the humans
#2
It's been a while since I've worked with SAS macros but what is happening to you makes perfect sense to me since you're writing to the same outfile every time. You could dynamically create the outfile name each time using the macro variables though. Possibly something like

Code:
PROC EXPORT DATA= dataset&year&mon2&day2

            OUTFILE= "D:\Data\dataset&year&mon2&day2..csv" 
            DBMS=CSV LABEL;
     PUTNAMES=YES;
RUN;
but like I said I haven't used it in quite some time. I don't know if you need those two periods before the csv - but I recall needing two of them at some point.
 
#3
It's been a while since I've worked with SAS macros but what is happening to you makes perfect sense to me since you're writing to the same outfile every time. You could dynamically create the outfile name each time using the macro variables though. Possibly something like

Code:
PROC EXPORT DATA= dataset&year&mon2&day2

            OUTFILE= "D:\Data\dataset&year&mon2&day2..csv" 
            DBMS=CSV LABEL;
     PUTNAMES=YES;
RUN;
but like I said I haven't used it in quite some time. I don't know if you need those two periods before the csv - but I recall needing two of them at some point.
You remember correctly (including the two periods, one to end the macro and one to specify the file extension).
 

Dason

Ambassador to the humans
#4
You remember correctly (including the two periods, one to end the macro and one to specify the file extension).
Awesome. I thought it was something like that but like I said I haven't actually used macros in quite some time. Thanks for the confirmation.
 
#5
I stacked the datasets, so I had fewer of them. And analysis in R doesn't depend on the number of datasets. I created a new dataset outside the macro that essentially stacks the dataset for a month at a time, and then exported using proc export outside the macro. It works out to be a bit easier this way.