Date: Sun, 19 Apr 2009 22:49:22 -0400
Reply-To: Paul Dorfman <sashole@BELLSOUTH.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Paul Dorfman <sashole@BELLSOUTH.NET>
Subject: Re: Chance to Make SAS-L History: Did You Know That...
Art,
Thank you for the kind words. I am quite flattered (and humbled), yet on
the other hand, frustrated at apparently being a failure as a teacher...
for if I had not been, I would not have failed to inculcate in the minds of
the attendees that one of the nifty things DoW affords is to do what needs
to be done before a BY-group is read from the next buffer just ONCE,
UNCONDITIONALLY, rather than upon IF FIRST.SEX comparison executed for
every observation read from the group. So, had I presented it properly, you
would have then likely coded (PUTs omitted):
data want;
do until(last.sex);
set have;
by sex;
if missing(height) then continue ;
sum = sum (sum, height);
n = sum (n, 1);
end;
average = sum / n ;
do until(last.sex);
set have;
by sex;
if missing(height) then continue ;
sum2 = sum (sum2, (height-average)**2) ;
end;
sd = sqrt (sum2 / (n - 1)) ;
do until(last.sex);
set have;
by sex;
if not(missing(height)) then z = (height - average) / sd ;
output;
end;
run;
Note the absence of RETAIN, CALL MISSING (the DATA step implied loop does
the clean-up automatically at the top of the step), and IF FIRST.
Kind regards
------------
Paul Dorfman
Jax, FL
------------
On Fri, 17 Apr 2009 20:41:13 -0400, Arthur Tabachneck <art297@NETSCAPE.NET>
wrote:
>Did you know that the DOW and Double-DOW can be extended to Tripple-DOW or
>even more complex configurations?
>
>At the last SGF I was fortunate to have taken in Paul Dorfman's
>presentation on what goes on, under the hood, when utilizing a Double-DOW
>approach.
>
>After all these years, the logic finally came through (i.e.,
"lightbulb!").
>
>A z-score shows how many standard deviations a score is from the mean.
>What if you wanted to know the height z-score, for male and female
>subjects, relative to the subjects' sex group mean score?
>
>Yes, of course, some SAS procs could accomplish the job more easily than
>the following code, but I, personally, was amazed that the multiple DOW
>approach could be extended beyond double processing (note: if you want to
>see what's going on, under the hood, delete the asterisks that precede the
>put statements):
>
>proc sort data=sashelp.class out=have;
> by sex;
>run;
>
>data want;
> retain sd average;
> do until(last.sex);
> set have;
> by sex;
> if first.sex then do;
> call missing(sum);
> call missing(n);
> end;
> if not(missing(height)) then do;
> sum+height;
> n+1;
> end;
> *put "first-loop: " _all_;
> end;
>
> do until(last.sex);
> set have;
> by sex;
> if first.sex then do;
> average=sum/n;
> call missing(sum2);
> end;
> if not(missing(height)) then do;
> sum2+(height-average)**2;
> end;
> *put "second-loop: " _all_;
> end;
>
> do until(last.sex);
> set have;
> by sex;
> if first.sex then do;
> sd=sqrt(sum2/(n-1));
> end;
> if not(missing(height)) then do;
> z=(height-average)/sd;
> end;
> output;
> *put "third-loop: " _all_;
> end;
>run;
>
>Art
|