|
On Fri, 8 Jul 2005 08:17:31 +0200, Rune Runnestø <rune@FASTLANE.NO> wrote:
>Hi,
>here is an example of som programming. Imagine there is some datasets, and
>the task is to loop through theese datasets and perform the same kind of
>operations on all. Seems to me like a good candidate for a loop. In the
case
>here, there is just two datasets, but in real there is a lot more. But
here,
>just two for simplicity.
>When you look at the two macros, there is just one word that makes them
>different, that is 'dykkerleger' and 'dykkerregister'. I want to make an
>array with these strings, and loop through the two of them. May be I can
>manage just with the outer macro, 'print_tp04' ?
>
>Can anyone suggest a looping code ? How do I make the array values in
>UPPERCASE in the text ?
>
>
>%macro print_tp04;
> %print_tp04_dykkerleger;
> %print_tp04_dykkerregister;
>%mend;
>
>%macro print_tp04_dykkerleger;
> %if &ant_tp04_dykkerleger_2_p > 0 %then
> %do;
> %global ant_tp04_dykkerleger;
> proc sql noprint;
> select sum(ant_dup) into :ant_tp04_dykkerleger
> from &lib..tp04_dykkerleger_3;
> run;
> %global pst_dup_dykkerleger;
> %let pst_dup_dykkerleger =
>%sysfunc(round(%sysevalf(100*&ant_tp04_dykkerleger/&ant_dykkerleger),.01));
> %let tabellnamn = tp04_dykkerleger_2_p;
> %finn_tot_ant_rec(&tabellnamn, &ant_tp04_dykkerleger_2_p);
> %finn_ant_rec_print(&print_alle, &prt_ant_default);
> ods rtf text="There is &ant_tp04_dykkerleger duplicate records
>in DYKKERLEGER.";
> ods rtf text="This is &pst_dup_dykkerleger percent of all the
>records in DYKKERLEGER.";
> ods rtf text="Below is shown &prt_ant of theese records.";
> proc print data=&lib..tp04_dykkerleger_2_p (obs=&prt_ant)
noobs
>label ;
> run;
> %end;
>%mend;
>%macro print_tp04_dykkerregister;
> %if &ant_tp04_ansatte_2_p > 0 %then
> %do;
> %global ant_tp04_ansatte;
> proc sql noprint;
> select sum(ant_dup) into :ant_tp04_ansatte
> from &lib..tp04_ansatte_3;
> run;
> %global pst_dup_ansatte;
> %let pst_dup_ansatte =
>%sysfunc(round(%sysevalf(100*&ant_tp04_ansatte/&ant_ansatte),.01));
> %let tabellnamn = tp04_ansatte_2_p;
> %finn_tot_ant_rec(&tabellnamn, &ant_tp04_ansatte_2_p);
> %finn_ant_rec_print(&print_alle, &prt_ant_default);
> ods rtf text="There is &ant_tp04_ansatte duplicate records in
>ANSATTE.";
> ods rtf text="This is &pst_dup_ansatte percent of all the
>records in ANSATTE.";
> ods rtf text="Below is shown &prt_ant of theese records.";
> proc print data=&lib..tp04_ansatte_2_p (obs=&prt_ant) noobs
>label ;
> run;
> %end;
>%mend;
>
>%print_tp04;
>
>Regards
>Rune
Hi Rune
%upcase() will uppercase in the macro environment
(I see you are in the fastlane of Norway ! )
For looping over processes, I published to sas-l, a macro %mLoopsX
The idea for which is like list processing:
that is :
do (something) macro parameter Execut=
value is the name of a macro
for each item in a list
macro parameter with=
value is a list of things
by default separated by blank
optional macro parameter withdlm=
supporting non-blank
with= list delimiter
You only have to create the "one-instance" processing
as a macro with a positional parameter which receives
its value from an item in the with= list
Does this facility provide what you seek ?
( %macro mLoopsX can be fornd in sas-L archives )
Peter Crawford
A simple example is like
%put prt pts = %mloopsx( execut= syo, with= ls ps center sysprintfont );
where syo is defined as
%macro syo( op ) ;
%sysfunc( getoption( &op, keyword ))
%mend;
|