🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 03-22-2021 08:24 AM
(1512 views)
Hi
I Where can I add that in this macro?
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Like that?
%macro prefix(code);
proc datasets;
delete tabel1-tabel5;
quit;
/*tabel 1*/
proc sql;
create table tabel1 as select
datetime() as dateformat ymdhms.,
lab,
ID,
from test
quit;
/*tabel2*/
proc sql;
create table tabel2 as select date format ymd.,
from test2
quit;
/*tabel3*/
proc sql;
create table tabel3 as select
date format ymdhms.,
ID,
CODE,
TESTED
from test3
quit;
/*tabel 4*/
data tabel4;
set test4;
format Dato ymd.;
run;
/*tabel 5 */
data tabel5;
set test5;
run;
%do i=1 %to 5;
proc export data=tabel&i. replace
outfile="&out_folder.\&code._COVID19_TABLE&i._&YYYYMMDD..csv"
dbms=dlm
;
delimiter=';';
quit;
/* try this ****/
filename in "&out_folder.\&code._COVID19_TABLE&i._&YYYYMMDD..csv" lrecl=1 recfm=n;
filename out "&out_folder.\&code..zip" member = "&code._COVID19_TABLE&i._&YYYYMMDD..csv" lrecl=1 recfm=n;
data _null_;
rc = fcopy("in", "out");
if rc ne 0 then
put "ERROR: for file &code._COVID19_TABLE&i._&YYYYMMDD..csv";
run;
filename in clear;
filename out clear;
/***************/
%end;
%mend;
%macro dummy_macro();
%if &nobs ne 4 %then %do;
filename mymail email from='test@test.dk' to=&mailto.
subject='ERROR -'
attach=("&logpath.&YYYYMMDD._log.log");
%end;
%else %do;
%prefix(1);
%prefix(2);
%prefix(3);
%prefix(4);
%prefix(5);
filename mymail email from='test@test.dk' to=&mailto.
subject='success';
ods listing file="&out_folder.\tesxtfile.txt";
data _null_;
file print;
text="The files has been uploaded succesfully";
put text;
run;
ods listing close;
%end;
%mend;
%dummy_macro();
Bart
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug
"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings
SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug
"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings
SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation
5 REPLIES 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Like that?
%macro prefix(code);
proc datasets;
delete tabel1-tabel5;
quit;
/*tabel 1*/
proc sql;
create table tabel1 as select
datetime() as dateformat ymdhms.,
lab,
ID,
from test
quit;
/*tabel2*/
proc sql;
create table tabel2 as select date format ymd.,
from test2
quit;
/*tabel3*/
proc sql;
create table tabel3 as select
date format ymdhms.,
ID,
CODE,
TESTED
from test3
quit;
/*tabel 4*/
data tabel4;
set test4;
format Dato ymd.;
run;
/*tabel 5 */
data tabel5;
set test5;
run;
%do i=1 %to 5;
proc export data=tabel&i. replace
outfile="&out_folder.\&code._COVID19_TABLE&i._&YYYYMMDD..csv"
dbms=dlm
;
delimiter=';';
quit;
/* try this ****/
filename in "&out_folder.\&code._COVID19_TABLE&i._&YYYYMMDD..csv" lrecl=1 recfm=n;
filename out "&out_folder.\&code..zip" member = "&code._COVID19_TABLE&i._&YYYYMMDD..csv" lrecl=1 recfm=n;
data _null_;
rc = fcopy("in", "out");
if rc ne 0 then
put "ERROR: for file &code._COVID19_TABLE&i._&YYYYMMDD..csv";
run;
filename in clear;
filename out clear;
/***************/
%end;
%mend;
%macro dummy_macro();
%if &nobs ne 4 %then %do;
filename mymail email from='test@test.dk' to=&mailto.
subject='ERROR -'
attach=("&logpath.&YYYYMMDD._log.log");
%end;
%else %do;
%prefix(1);
%prefix(2);
%prefix(3);
%prefix(4);
%prefix(5);
filename mymail email from='test@test.dk' to=&mailto.
subject='success';
ods listing file="&out_folder.\tesxtfile.txt";
data _null_;
file print;
text="The files has been uploaded succesfully";
put text;
run;
ods listing close;
%end;
%mend;
%dummy_macro();
Bart
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug
"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings
SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug
"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings
SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It says
ERROR 23-2: Invalid option name member.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Sorry, should be:
filename out ZIP "&out_folder.\&code..zip" member = "&code._COVID19_TABLE&i._&YYYYMMDD..csv" lrecl=1 recfm=n;
B
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug
"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings
SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug
"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings
SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you it worked - in my folder I willl get the CSV files seperate from the ZIP files - is there any way to ONLY have ZIP files in the folder?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
try this:
/* try this */
filename out ZIP "&out_folder.\&code..zip" member = "&code._COVID19_TABLE&i._&YYYYMMDD..csv" lrecl=1 recfm=n;
proc export data=tabel&i. replace
outfile=out
dbms=dlm
;
delimiter=';';
quit;
and drop my code between:
/* try this ****/
and
/***************/
If it fails, the try to replace data step from my code with:
data _null_;
rc = fcopy("in", "out");
if rc ne 0 then
put "ERROR: for file &code._COVID19_TABLE&i._&YYYYMMDD..csv";
else fdelete("in");
run;
All the best
Bart
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug
"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings
SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug
"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings
SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation