Date: Thu, 24 Feb 2000 16:24:51 -0500
Reply-To: Jeremy Miller <millerj@CALIB.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jeremy Miller <millerj@CALIB.COM>
Subject: Re: Macro question
Content-Type: text/plain; charset="iso-8859-1"
Perhaps when being so condescending, you should make sure your solutions
work:
> data result (keep = site_id clientid x scr res);
> set urn(keep=site_id clientid scr1-scr45 res1-res45);
> array _scr (45) scr1-scr45 ;
> array _res (45) res1-res45 ;
> do x = 1 to dim ( _scr ) ;
> if _scr(x) ^=. and _res(x) ^=. then output ;
> end ;
> run ;
Given that the variables 'scr' and 'res' are never referenced, this solution
to my "tragedy" will not work. You must first add these lines:
do x=1 to dim{_scr};
if _scr{x}^=. and _res{x}^=. then do;
scr=_scr{x};
res=_res{x};
output;
end;
end;
run;
Now on to the hubris: why is it necessary to be so condescending when
replying to a public forum? To most people, the SAS-L is probably a place
to pick up new tricks and have questions they are stuck on answered.
However, who wants to participate in something where there is the
possibility of public humiliation. I don't know about you, Ian Whitlock
<WHITLOI1@westat.com>, but I actually happen to make mistakes, usually
several times a day. SAS-L is a place where I can have the opportunity to
have the mistakes I make corrected and learn from them. So, this I do not
consider a tragedy. Of course, if we were all as good as you, there would
be no need for a SAS-L because we would have no questions to post because we
knew it all.
However, I must thank you. Once again, SAS-L has helped my poor choices in
coding. Your "advice" on using an array instead of a macro was beneficial
because it removed the concatenation step.
Thanks for the help,
Jeremy T. Miller
Caliber Associates
10530 Rosehaven St.
STE 400
Fairfax, VA 22030
(703) 219-4332
www.calib.com
> -----Original Message-----
> From: WHITLOI1@westat.com [SMTP:WHITLOI1@westat.com]
> Sent: Thursday, February 24, 2000 2:12 PM
> To: Jeremy Miller; SAS-L@LISTSERV.UGA.EDU
> Subject: Re:Macro question
>
> Subject: Macro question
> Summary: Good programming is better than macro
> Respondent: Ian Whitlock <whitloi1@westat.com>
>
> Jeremy Miller <millerj@CALIB.COM> has written a macro to split a
> data set into 45 pieces and now wants to concatenate the pieces.
> His first macro is
>
> > %macro datasets;
> > %do i=1 %to 45;
> > data dat&i(rename=(scr&i=scr res&i=res));
> > set urn(keep=site_id clientid scr&i res&i);
> > run;
> > %end;
> > %mend datasets;
>
> His question is how to write the second macro when for two data sets
> he has
>
> > data dat3;
> > set dat1 dat2;
> > if scr=. | res=. then delete;
> > run;
>
> There are two simple macro answers to this question, but the
> tragedy is that it shouldn't have been done in the first place. No
> macro was necessary or desirable.
>
> data result (keep = site_id clientid x scr res);
> set urn(keep=site_id clientid scr1-scr45 res1-res45);
> array _scr (45) scr1-scr45 ;
> array _res (45) res1-res45 ;
> do x = 1 to dim ( _scr ) ;
> if _scr(x) ^=. and _res(x) ^=. then output ;
> end ;
> run ;
>
> proc sort data = result ;
> by x ;
> run ;
>
> The sort is not needed if the order doesn't matter. Then removing X
> from the KEEP list would be possible, but at the expense of losing
> information. However that information was also lost in the question.
>
> Now let's look at two macro answers.
>
> > %macro datasets;
> > %do i=1 %to 45;
> > data dat&i(rename=(scr&i=scr res&i=res));
> > set urn(keep=site_id clientid scr&i res&i);
> if _scr&i ^=. and _res&i ^=. ;
> > run;
> proc append base = result data = dat&i ;
> run ;
> > %end;
> > %mend datasets;
>
> or
>
> > %macro datasets;
> %local dslist ;
> > %do i=1 %to 45;
> %let dslist = &dslist dat&i ;
> > data dat&i(rename=(scr&i=scr res&i=res));
> > set urn(keep=site_id clientid scr&i res&i);
> > run;
> > %end;
>
> > data dat3;
> set &dslist ;
> > if scr=. | res=. then delete;
> > run;
>
> > %mend datasets;
>
> Of course, there are many more answers with and without macro or
> arrays; but the real question is, how have we come teach programmers
> about SAS macro before they have learned good SAS programming
> techniques?
>
> At Westat the answer is that everyone is using SAS macro so new
> beginning programmers must learn some macro to be able to read the
> the programs that they have to modify. The cost in terms of long
> complex programs has never been estimated nor the method even
> questioned. Any different, anywhere else?
>
> Ian Whitlock
|