Hi.
I have a code that makes 25 CSV files.
These files are based on 5 regions and each region has 5 files.
I want to create 5 zipfiles for each regions, which includes the 5 files for each region.
I use this code to export to csv file (the 25 files), i use it in a macro to get the name of the file, so i my folder i get 25 files looking like this:
A_COVID19_TAB1_20210317.csv
A_COVID19_TAB2_20210317.csv
A_COVID19_TAB3_20210317.csv
A_COVID19_TAB4_20210317.csv
A_COVID19_TAB5_20210317.csv
B_COVID19_TAB1_20210317.csv
B_COVID19_TAB2_20210317.csv
B_COVID19_TAB3_20210317.csv
B_COVID19_TAB4_20210317.csv
B_COVID19_TAB5_20210317.csv
....
same for regioncode C, D, E
I want to make 5 zip files for each code named:
A_COVID19_20210317.zip
B_COVID19_20210317.zip
C_COVID19_20210317.zip
D_COVID19_20210317.zip
E_COVID19_20210317.zip
%let YYYYMMDD=%sysfunc(inputn(&DDMMMYYYY_h,best12.), YYMMDDN.6);
%macro regioncode(region);
%do i=1 %to 5;
proc export data=tabel&i. replace
outfile="&out_folder.\®ion._COVID19_TAB&i._&YYYYMMDD..csv"
dbms=dlm
;
delimiter=';';
quit;
%regioncode(A);
%regioncode(B);
%regioncode(C);
%regioncode(D);
%regioncode(E);
%end;
%mend;
You can write your csv directly as a member into a ZIP file:
filename zipfile zip '/folders/myfolders/myfile.zip';
data _null_;
set sashelp.class;
file zipfile(class.csv) dlm=";" dsd;
if _n_ = 1 then put "name;sex;age";
put name sex age;
run;
data _null_;
set sashelp.cars;
file zipfile(cars.csv) dlm=";" dsd;
if _n_ = 1 then put "make;model";
put make model;
run;
filename zipfile clear;
Note that the
fileref(member)
notation cannot be used in PROC EXPORT (it accepts only physical filenames), so you have to use DATA _NULL_ steps to write the csv content.
Can I do this in the same Macro as shown ?
Do all datasets have the same structure?
I have table 1 to 5 - they all contain different data/varables but same structure and formats
That is a contradiction. If they have different variables, they can't have the same structure. "Same structure" means the same variables with the same types and attributes.
@mmea wrote:
I have table 1 to 5 - they all contain different data/varables but same structure and formats
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.