Date: Sat, 10 Dec 2005 03:29:29 +0000
Reply-To: toby dunn <tobydunn@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: toby dunn <tobydunn@HOTMAIL.COM>
Subject: Re: MAcro Design was (Re: Macro quoting essentials)
In-Reply-To: <1134163236.565260.78700@g49g2000cwa.googlegroups.com>
Content-Type: text/plain; format=flowed
Lei,
Opps I forgot to declare my macro vars as local. sorry it really has been a
long day..... Hey who has the beer, beer nuts, and fireplace ready...
%macro printz(Help = No , DataSets = ) ;
%local I Stop ;
%if ( %upcase(&Help) = YES ) %then %do ;
%put Help on Macro Printz: ;
%put Ha Ha Ha you really thought you were going to get help. ;
%put End O Help ;
%end ;
%else %if ( %upcase(&Help) = NO ) %then %do ;
%let Stop = %eval( %length(&datasets) -
%length(%sysfunc(compress(&DataSets))) + 1 ) ;
%Do I = 1 %to &Stop ;
proc print
data = %scan(&DataSets , &i , ' ') width = minimum ;
run ;
%end ;
%end ;
%else %do ;
%put You have entered an invalid value for parameter Help. ;
%put Valid values are: Yes or No. ;
%end ;
%mend ;
Toby Dunn
From: Lei Zhang <lzhang9830@YAHOO.COM>
Reply-To: lzhang9830@YAHOO.COM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: MAcro Design was (Re: Macro quoting essentials)
Date: Fri, 9 Dec 2005 13:20:36 -0800
MIME-Version: 1.0
Received: from bay0-mc6-f12.bay0.hotmail.com ([65.54.244.180]) by
bay0-imc3-s30.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.211); Fri, 9
Dec 2005 14:40:06 -0800
Received: from mailgw.cc.uga.edu ([128.192.1.101]) by
bay0-mc6-f12.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.211); Fri, 9
Dec 2005 13:26:13 -0800
Received: from listserv.cc.uga.edu (listserv.uga.edu [128.192.1.75])by
mailgw.cc.uga.edu (8.12.11/8.12.11) with ESMTP id jB9JSAaJ017158;Fri, 9 Dec
2005 16:25:04 -0500
Received: from LISTSERV.UGA.EDU by LISTSERV.UGA.EDU (LISTSERV-TCP/IP release
1.8d) with spool id 4453784 for SAS-L@LISTSERV.UGA.EDU; Fri, 9 Dec
2005 16:25:04 -0500
Received: from alfredo.cc.uga.edu (alfredo.cc.uga.edu [128.192.1.77]) by
listserv.cc.uga.edu (8.12.11/8.12.11) with ESMTP id jB9LP4A7003387
for <sas-l@listserv.uga.edu>; Fri, 9 Dec 2005 16:25:04 -0500
Received: from alfredo.cc.uga.edu (localhost.localdomain [127.0.0.1]) by
alfredo.cc.uga.edu (8.12.11/8.12.11) with ESMTP id jB9LP3tt028303 for
<sas-l@listserv.uga.edu>; Fri, 9 Dec 2005 16:25:03 -0500
Received: (from news@localhost) by alfredo.cc.uga.edu
(8.12.11/8.12.11/Submit) id jB9LP3mY028298 for
sas-l@listserv.uga.edu; Fri, 9 Dec 2005 16:25:03 -0500
X-Message-Info: eW1r7T5OXW6xHww6ErGV7Xm2saSKj1y/xFZJhYuj57Q=
X-Authentication-Warning: alfredo.cc.uga.edu: news set sender to
saslmnt@listserv.uga.edu using -f
X-Newsgroups: comp.soft-sys.sas
Lines: 50
References: <BAY101-F10DEF612E041FFF7F7E28ADE450@phx.gbl>
X-Complaints-To: groups-abuse@google.com
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET
CLR 1.1.4322),gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: g49g2000cwa.googlegroups.com; posting-host=138.89.66.123;
posting-account=REqrIgwAAACNBzNoQmFZtkNuHHRroJZ6
X-Scanned-By: Digested by UGA Mail Gateway on 128.192.1.75
Organization: http://groups.google.com
Comments: To: sas-l@uga.edu
Return-Path: owner-sas-l@LISTSERV.UGA.EDU
X-OriginalArrivalTime: 09 Dec 2005 21:26:14.0285 (UTC)
FILETIME=[2EDE5BD0:01C5FD07]
Hi Toby,
Attached is the example macro with online help functionality that
I purpose.
The macro is modified from your %printz by adding pbuff option. To get
onlne help,
a macro user can simply type the macro name and run it. He/she don't
have to
remenber or type any other extra parameters for help. For example,
type
%Printz;
the macro show the usage as follows:
Help on Macro %Printz:
...
End of Help
A user can also print one or more datasets with its normal parameters:
%Printz(sashelp.class sashelp.vstable);
I will appreciate if you have other approach without using vararg
feature. Thanks.
The source code is listed as follows for your quick review:
%macro printz(x)/parmbuff;
%if %length(&syspbuff)= 0 or %length(&syspbuff)=2 %then %do;
/* Print help */
%put;
%put Help on Macro %nrstr(%%Printz):;
%put ...;
%put End of Help;
%end; %else %do;
/* Main */
%let num=1;
%let dsname=%scan(&syspbuff,&num, %str(%(%), ));
%do %while(%length(&dsname));
proc print data=&dsname width=minimum;
run;
%let num=%eval(&num+1);
%let dsname=%scan(&syspbuff,&num, %str(%(%), ));
%end;
%end;
%mend;