Date: Wed, 23 Apr 1997 10:37:30 +0500
Reply-To: Bernard Tremblay <bernard@CAPITALE.QC.CA>
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: Bernard Tremblay <bernard@CAPITALE.QC.CA>
Subject: Re: Macro Variable question
Hi,
You have to scan the dataset first to know the values
of "group" and then have provision to handle the case where you
do not select on group (all case).
Here is the code:
%macro loopfor(var,file,mymac);
%*** This macro loop for each value of var in file ;
%*** ---------------------------------------------;
%*** var = variable name to test ;
%*** file = SAS file for input ;
%*** mymac= name of macro to repeat for each value ;
%*** ---------------------------------------------;
%***;
*** first obtain values ***;
proc freq data=&file;
table &var/ out=values ;
run;
*** second call macro for each value and at last for all values ***;
data _null_;
set values end=eof;
call execute('%'||"&mymac('"||&var||"');"); /* each group */
if eof then call execute('%'||"&maymac(_all_);"); /* all groups */
run;
%mend;
But you shoul modify you macro to handle the case
where you want all values:
%macro group(select);
data groups;
set groups1 ;
where %if &select = _all_ %else %str(;); /* null where */
%then %str(group=&select ;); /*select group*/
/*** you have to put your code to repeat here if any ***/
run;
%mend group;
All you have to do then is to call the main macro:
%loopfor(group,group1,group);
NB: This is untested code. You'll have to check it out ...
Hope it helps,
Bernard Tremblay
\\\|///
\\ - - //
( @ @ )
+------oOOo-(_)-oOOo----------+---------------------------------+
| Bernard Tremblay | |
| La Capitale | Tel: (418) 646-2401 |
| | Fax: (418) 646-5960 |
| | Int: bernard@capitale.qc.ca |
+-----------------------------+---------------------------------+
| Imaginasys enr | Res: (418) 878-4447 |
| | Int: bertrem@quebectel.com |
+---------------Oooo----------+---------------------------------+
oooO ( )
( ) ) /
\ ( (_/
\_)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>From owner-sas-l@UGA.CC.UGA.EDU Wed Apr 23 09:50 EDT 1997
>>>Date: Wed, 23 Apr 1997 09:43:48 -0400
>>>From: DIANE GOLDSCHMIDT <DGOLDSCH@BCBSCT.COM>
>>>Subject: Macro Variable question
>>>To: Multiple recipients of list SAS-L <SAS-L@UGA.CC.UGA.EDU>
>>>
>>>I have a data step I want to run repeatedly. First, for all groups, then for
>>>each individual group. _ALL_ doesn't work.
>>>
>>>%macro group(select);
>>>data groups;
>>> set groups1;
>>>if group = &select;
>>>%mend group;
>>>
>>>%group(????); /* how do I do this for all groups??? */
>>>%group('102');
>>>%group('115');
>>>%group('118');
>>>