Date: Mon, 13 Dec 2010 17:00:39 +0000
Reply-To: "Fehd, Ronald J. (CDC/OCOO/ITSO)" <rjf2@CDC.GOV>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Fehd, Ronald J. (CDC/OCOO/ITSO)" <rjf2@CDC.GOV>
Subject: Re: Potential DOW-Loop Problem?
In-Reply-To: <AANLkTimtgc18+DHRhvbr1iAZYqGrigUVHNBoaf0dOCbB@mail.gmail.com>
Content-Type: text/plain; charset="us-ascii"
see also:
http://www.sascommunity.org/wiki/Do_until_last.var
> -----Original Message-----
> From: owner-sas-l@listserv.uga.edu [mailto:owner-sas-
> l@listserv.uga.edu] On Behalf Of Dominik Becker
> Sent: Saturday, December 11, 2010 6:27 AM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Re: Potential DOW-Loop Problem?
>
> Many thanks, Mark, for this very detailed answer to my problem. Now I
> should be able to learn how to DOW!
> Sorry, Gerhard, that I did not provide enough information for you to
> help me. Additional to the paper that was mentioned by Nat, I found
> the following document that could be useful for the prospective reader
> of this discussion:
>
> www.nesug.org/proceedings/nesug08/hw/hw02.pdf
>
> Thanks for all answers
> Dominik
>
>
>
> 2010/12/10 Nat Wooding <nathani@verizon.net>:
> > Gerhard
> >
> > Take a look at Paul Dorfman's recent NESUG paper.
> >
> > Nat Wooding
> >
> > http://www.nesug.org/Proceedings/nesug10/hw/hw03.pdf
> >
> >
> >
> > -----Original Message-----
> > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
> Gerhard
> > Hellriegel
> > Sent: Friday, December 10, 2010 2:05 PM
> > To: SAS-L@LISTSERV.UGA.EDU
> > Subject: Re: Potential DOW-Loop Problem?
> >
> > I'm missing the "example code"! You should at least TRY to do your
> > homework yourself before you ask for help. If there is some code,
> there
> > would be someone for sure to help you finding some mistakes.
> >
> > By the way: what is a DOW-loop? A Day-Of-Week loop? A Dust-Or-Water
> loop?
> > Don't know what that is...
> >
> > And note, that in SAS most of the loop constructs are automatic. You
> don't
> > need a loop for stepping through sashelp.class.
> >
> > data a;
> > set sashelp.class;
> > run;
> >
> > is enough.
> >
> > Gerhard
>
>
>
> 2010/12/10 Keintz, H. Mark <mkeintz@wharton.upenn.edu>:
> > Domonik:
> >
> > Yes, your task is well-suited to the DOW loop technique. In fact
> it's a very representative problem solved by the "double DOW", in which
> you:
> >
> > 1. Read all records for a group, tracking certain summary measures
> along the way.
> >
> > 2. At the end of the group, calculate other summary measures.
> >
> > 3. Reread all records for the group, this time outputing those
> records, along with the relevant summry measures.
> >
> > Assume you have:
> >
> > data have;
> > input country year demo @@;
> > datalines;
> > 1 1 0 1 2 0 1 3 1 1 4 1 1 5 1
> > 2 1 1 2 2 1 2 3 1 2 4 1 2 5 1
> > 3 1 0 3 2 0 3 3 0 3 4 0 3 5 0
> > 4 1 1 4 2 1 4 3 0 4 4 0 4 5 0
> > run;
> >
> > Then use:
> >
> > data want;
> > ** Read a group and count years of democracy (duration) **;
> > do until (last.country);
> > set have;
> > by country;
> > duration=sum(duration,demo);
> > end;
> >
> > ** Finish the summary measures **;
> > if duration=0 then do; ** If a stable autocracy... **;
> > censor=.;
> > duration=.;
> > end;
> > else if duration=5 then censor=0; ** If stable democracy **;
> > else censor=1-demo; ** Otherwise use last DEMO to indicate type
> of change **;
> >
> > ** Reread and output **;
> > do until (last.country);
> > set have;
> > by country;
> > output;
> > end;
> > run;
> >
> >
> > This program assumes:
> >
> > 1. Data are sorted by COUNTRY YEAR.
> >
> > 2. Over the entire time span, there is at most one change (that's
> why the "else censor=1-demo;" statement works).
> >
> > 3. There are exactly 5 years for each country.
> >
> > Regards,
> > Mark
>
> >
> >
> >
> >
> > On Fri, 10 Dec 2010 18:57:54 +0100, Dominik Becker
> > <dombecksoz@GOOGLEMAIL.COM> wrote:
> >
> >>Dear all,
> >>
> >>I am quite new to SAS' looping facilities, so I'd be glad if someone
> >>could help me out. Web research suggested that it could be related to
> >>a DOW-Loop, but I'm neither sure about this nor able to implement
> this
> >>on my own.
> >>
> >>I have data that indicate whether a country was an autocracy (demo=0)
> >>or a democracy (demo=1) in a certain year. Now three things can
> happen
> >>over time: An autocracy can become a democracy, both autocracies and
> >>democracies can remain stable, and democracies may break down.
> >>My aim is to compute a 'censor' variable that takes 1 if a former
> >>democracy breaks down, 0 for both stable democracies and democratized
> >>countries (i.e. the censored ones), and missing for stable
> >>autocracies.
> >>
> >>In a second step, I would have to specify in a variable 'duration'
> how
> >>long each democracy persists.
> >>
> >>Below I attach some illustrative code. The last two columns is what I
> >>would like to achieve. Thanks a lot for any suggestions!
> >>
> >>Best,
> >>Dominik
> >>
> >>
> >>*** EXAMPLE CODE ***;
> >>
> >>country year demo censor duration
> >>1 1 0 0 3
> >>1 2 0 0 3
> >>1 3 1 0 3
> >>1 4 1 0 3
> >>1 5 1 0 3
> >>2 1 1 0 5
> >>2 2 1 0 5
> >>2 3 1 0 5
> >>2 4 1 0 5
> >>2 5 1 0 5
> >>3 1 0 . .
> >>3 2 0 . .
> >>3 3 0 . .
> >>3 4 0 . .
> >>3 5 0 . .
> >>4 1 1 1 2
> >>4 2 1 1 2
> >>4 3 0 1 2
> >>4 4 0 1 2
> >>4 5 0 1 2
> >
|