<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Creating ZIP files with different files in them in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Creating-ZIP-files-with-different-files-in-them/m-p/767402#M30754</link>
    <description>&lt;P&gt;Do you need the work datasets?&amp;nbsp; Or do you just need the CSV files?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would change the %DO loop to looping over a list of datasets.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dslist=table1 table3 table5 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you can add a conditional to change the list of datasets based on the REGION value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if "&amp;amp;region" = "&lt;SPAN&gt;1082&lt;/SPAN&gt;" %then %let dslist=&amp;amp;dslist table2 table4 table6;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now the %DO loop could be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do i=1 %to %sysfunc(countw(&amp;amp;dslist));
  %let dsname=%scan(&amp;amp;dslist,&amp;amp;i);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And just replace TABLE&amp;amp;I with &amp;amp;DSNAME in the body of the %DO loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 13 Sep 2021 13:02:01 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-09-13T13:02:01Z</dc:date>
    <item>
      <title>Creating ZIP files with different files in them</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-ZIP-files-with-different-files-in-them/m-p/767397#M30752</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;I have this script of code where I have made som datasets beforehand. Afterwards I export them as CSV files and into their matching zipfiles (based on region codes). It has to be this way as it is an automatic code thats running everyday&lt;/P&gt;
&lt;P&gt;The code now put the same 3 files in each zip folder for each region code - but now 2 of the region codes should have 3 more files/tables in the folder (table2,table4, table6) - only region code 1082 should have these files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With the code below all regioncodes (1081, 1082, 1083, 1084, 1085) get the same files in their own zip file - I only want table 2, 4, 6 for code 1082.&lt;/P&gt;
&lt;P&gt;How can I do that so ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro leverance(region_code);

proc datasets;
delete table1-table6;
quit;


/*tabel 1*/

proc sql;
create table table1 as select 
datetime() as date format ymdhms.,
LAR,
EX,
ID,
TEST,
from basis_sample2
where region_adr=&amp;amp;region or region_lab=&amp;amp;region;
quit;


/*tabel2*/
data table2;
set AGE;
if region = &amp;amp;region;
run;


/*table3*/
proc sql;
create table table3 as select 
DATE format ymdhms.,
AGE,
ID,
CODE
from REG 
where regioncode=&amp;amp;region;
quit;


/*table4*/

data table4;
set municipality;
if region = &amp;amp;region;
run;


/*table5*/
data table5;
set VACC_data;
if region=&amp;amp;region;
run;


/*tabel 6*/

data table6;
set SEX;
if region = &amp;amp;region;
run;



%do i=1 %to 6;

proc export data=tabel&amp;amp;i. replace
  outfile="&amp;amp;out_folder_CSV.\&amp;amp;region._COVID19_TABLE&amp;amp;i..csv"
  dbms=dlm
;
delimiter=';';
quit;


/*make zip files****/
filename in "&amp;amp;out_folder_CSV.\&amp;amp;region._COVID19_TABLE&amp;amp;i..csv" lrecl=1 recfm=n;
filename out ZIP "&amp;amp;out_folder.\&amp;amp;region._COVID19_FOLDER.zip" member = "&amp;amp;region._COVID19_TABLE&amp;amp;i..sv" lrecl=1 recfm=n;

data _null_;
  rc = fcopy("in", "out");
  if rc ne 0 then 
    put "ERROR: for file &amp;amp;region._COVID19_RETUR_TABLE&amp;amp;i..csv";
run;

filename in clear;
filename out clear;
/***************/

%end;
%mend;



%macro dummy_macro();
%if &amp;amp;nobs ne 4 %then %do; 

filename mymail email from='TEST@TEST.dk' to=&amp;amp;mailto.
         subject='ERROR '
        

data _null_;
  file mymail;
  put 'TEST';
run;
%end;
%else %do;

%leverance(1081);
%leverance(1082);
%leverance(1083);
%leverance(1084);
%leverance(1085);

filename mymail email from='TEST@TEST.dk' to=&amp;amp;mailto.
         subject='data to the regions';

data _null_;
  file mymail;
  put 'SUCCES';
run;


%end;
%mend;

%dummy_macro();
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 12:41:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-ZIP-files-with-different-files-in-them/m-p/767397#M30752</guid>
      <dc:creator>mmea</dc:creator>
      <dc:date>2021-09-13T12:41:31Z</dc:date>
    </item>
    <item>
      <title>Re: Creating ZIP files with different files in them</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-ZIP-files-with-different-files-in-them/m-p/767400#M30753</link>
      <description>&lt;P&gt;Maybe like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro leverance(region_code, tables = 1 3 5)/minoperator;

proc datasets;
delete table1-table6;
quit;


/*tabel 1*/

proc sql;
create table table1 as select 
datetime() as date format ymdhms.,
LAR,
EX,
ID,
TEST,
from basis_sample2
where region_adr=&amp;amp;region or region_lab=&amp;amp;region;
quit;


/*tabel2*/
data table2;
set AGE;
if region = &amp;amp;region;
run;


/*table3*/
proc sql;
create table table3 as select 
DATE format ymdhms.,
AGE,
ID,
CODE
from REG 
where regioncode=&amp;amp;region;
quit;


/*table4*/

data table4;
set municipality;
if region = &amp;amp;region;
run;


/*table5*/
data table5;
set VACC_data;
if region=&amp;amp;region;
run;


/*tabel 6*/

data table6;
set SEX;
if region = &amp;amp;region;
run;



%do i=1 %to 6;
%if &amp;amp;i. in (&amp;amp;tables.) %then
%do;
proc export data=tabel&amp;amp;i. replace
  outfile="&amp;amp;out_folder_CSV.\&amp;amp;region._COVID19_TABLE&amp;amp;i..csv"
  dbms=dlm
;
delimiter=';';
quit;


/*make zip files****/
filename in "&amp;amp;out_folder_CSV.\&amp;amp;region._COVID19_TABLE&amp;amp;i..csv" lrecl=1 recfm=n;
filename out ZIP "&amp;amp;out_folder.\&amp;amp;region._COVID19_FOLDER.zip" member = "&amp;amp;region._COVID19_TABLE&amp;amp;i..sv" lrecl=1 recfm=n;

data _null_;
  rc = fcopy("in", "out");
  if rc ne 0 then 
    put "ERROR: for file &amp;amp;region._COVID19_RETUR_TABLE&amp;amp;i..csv";
run;

filename in clear;
filename out clear;
/***************/
%end;
%end;
%mend;



%macro dummy_macro();
%if &amp;amp;nobs ne 4 %then %do; 

filename mymail email from='TEST@TEST.dk' to=&amp;amp;mailto.
         subject='ERROR '
        

data _null_;
  file mymail;
  put 'TEST';
run;
%end;
%else %do;

%leverance(1081);
%leverance(1082, tables = 1 2 3 4 5 6);
%leverance(1083);
%leverance(1084);
%leverance(1085);

filename mymail email from='TEST@TEST.dk' to=&amp;amp;mailto.
         subject='data to the regions';

data _null_;
  file mymail;
  put 'SUCCES';
run;


%end;
%mend;

%dummy_macro();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 12:54:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-ZIP-files-with-different-files-in-them/m-p/767400#M30753</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-09-13T12:54:12Z</dc:date>
    </item>
    <item>
      <title>Re: Creating ZIP files with different files in them</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-ZIP-files-with-different-files-in-them/m-p/767402#M30754</link>
      <description>&lt;P&gt;Do you need the work datasets?&amp;nbsp; Or do you just need the CSV files?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would change the %DO loop to looping over a list of datasets.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dslist=table1 table3 table5 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you can add a conditional to change the list of datasets based on the REGION value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if "&amp;amp;region" = "&lt;SPAN&gt;1082&lt;/SPAN&gt;" %then %let dslist=&amp;amp;dslist table2 table4 table6;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now the %DO loop could be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do i=1 %to %sysfunc(countw(&amp;amp;dslist));
  %let dsname=%scan(&amp;amp;dslist,&amp;amp;i);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And just replace TABLE&amp;amp;I with &amp;amp;DSNAME in the body of the %DO loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 13:02:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-ZIP-files-with-different-files-in-them/m-p/767402#M30754</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-13T13:02:01Z</dc:date>
    </item>
  </channel>
</rss>

