BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mmea
Quartz | Level 8

Hi 

I Where can I add that in this macro?

1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15

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



View solution in original post

5 REPLIES 5
yabwon
Onyx | Level 15

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



mmea
Quartz | Level 8

It says 

 

ERROR 23-2: Invalid option name member.

yabwon
Onyx | Level 15

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



mmea
Quartz | Level 8

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?

 

yabwon
Onyx | Level 15

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



SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 5 replies
  • 1029 views
  • 0 likes
  • 2 in conversation