Example 2: Example: Publishing in a Macro

The following example builds a package, publishes the package to a channel that is defined in the SAS Metadata Repository, and then explicitly publishes to one queue. This example uses macro variables rather than the DATA step, which allows you the flexibility to use CALL routines throughout your code, as other processing completes. This example also illustrates how publish CALL routines are used with other SAS statements.
%macro chkrc(function);
%if &rc = 0 %then %put "NOTE: &function succeeded.";
%else %do;
   %let msg= %sysfunc(sysmsg());
   %put &function failed - &msg
%end;
%mend;

%let packageId = 0;
%let nameValue=type=(test) coverage=(filtering,
   transports);
%let rc = 0;
%let packageId = 0;
%let description=main results package;
%syscall package_begin(packageId,description, nameValue, rc);
%chkrc(Package Begin);

%let gifpid=0;
%let description=Gif nested package. ;
%let nameValue=;
%syscall package_begin(gifpid, description,
   nameValue, rc);
%chkrc(Package Begin);

filename f 'c:\frame.html';
filename c 'c:\contents.html';
filename p 'c:\page.html';
filename b 'c:\body.html';
ods html frame = f
   contents =c(url="contents.html")
      body = b(url="body.html")
   page=p(url="page.html");

/* run some data steps/procs to generate ODS output */
data b;
   do i= 1 to 1000;
   output;
end;run;

%let nameValue=;
%let description= B, testing dataset;
%let libname = WORK;
%let memname= B;
%syscall insert_dataset(packageId,libname, memname,
   description, nameValue, rc);
%chkrc(Insert Dataset);

data emp;
input fname $ lname $ ages state $ siblings;
cards;
Steph Jones 32 NC 4
Richard Long 40 NC 2
Mary Robins 74 NC 1
Kai Mack 3 NC 1
Dakota Wills 1 NC 1
Paul Thomas 79 NC 8
Digger Johnson 5 NC 0
Coby Gregson 1 NC 0
Julie Thomson 6 NC 1
Amy Billins 3 NC 1
Brian Gere 16 HA 1
Richard Carter 17 HA 1
Diane Ford 48 CO 4
Pamela Aarons 42 HA 4
Joe Ashford 44 WA 10
Michael Clark 23 IL 1
Michael Harris 31 NM 4
Ken Porter 28 NC 1
Brian Harrison 27 NC 1
Laurie Smith 32 NC 1
Kevin Black 33 NC 1
Steve Jackson 33 NC 1
run;
quit;

%let nameValue= type=report, topic=census;
%let description=North Carolina residents.;
%let libname = WORK;
%let memname= EMP;
%syscall insert_dataset(packageId, libname, memname,
   description, nameValue, rc);
%chkrc(Insert Dataset);

proc print;run;
proc contents;run;
ods html close;

%let body=fileref:b;
%let frame=fileref:f;
%let contents=fileref:c;
%let pages=fileref:p;
%let description=Generated ODS output.;
%let curl="contents.html";
%let burl = "body.html";
%let furl = "frame.html";
%let purl = "page.html";
%syscall insert_html(packageId, body, burl, frame,
   frameurl, contents, curl, pages, purl,
   description, nameValue, rc);
%chkrc(Insert Html);

/* insert nested package */
%syscall insert_package(packageId, gifpid,rc);
%chkrc(Insert Package);

%let giffile=filename:Boeing747.gif;
%let description=New 747 paint scheme.;
%let filetype = text;
%let mimetype = %quote(Image/gif);
%syscall insert_file(gifpid, giffile, filetype,
   mimetype, description, nameValue, rc);
%chkrc(Insert File);

/* publish to the filter test channel
   defined in the SAS Metadata Repository */
%let storeinfo=
   "SAS-OMA://alpair01.sys.com:8561";
%let channel1=FilterTest;
%let properties='channel_store, subject, metauser, metapass';
%let subject=Filter Testing Results;
%let user = myUserName;
%let password = myPassword;
%let publishType=to_subscribers;
CALL PACKAGE_PUBLISH(packageId, "TO_SUBSCRIBERS", rc,
   properties, storeinfo, subject, user, password,
   channel1);
%chkrc(publish package);

/* publish one queue */
%let property=;
%let publishType = to_queue;
%let queueName=mqseries://JSMITH:LOCAL;
%syscall package_publish(packageId, publishType,
   rc, property, queueName);
%chkrc(publish package);

%syscall package_end(packageId,rc);
%chkrc(Package End);

run;
quit;