Hi Toby and Ian,
Thanks for your input. I added another two if statements after "if %y >=10":
if x<10 then
if x>10 then
It was a little bit tedious.
Ian, you raised a good question about apply people of today's
mortality to people in the future. but I dunno other way around. Of
cuz, this issue is out of scope for this user group.
On 7/8/07, iw1junk@comcast.net <iw1junk@comcast.net> wrote:
> Summary: Simplify
> #iw-value=1
>
> Toby,
>
> You have a funny way of making simple things look complex. Consider using
>
> data base ( drop = i ) ;
> set base2000 ;
> do i = 1 to 20 ;
> NewAge = Age + I ;
> Year = 2000 + I ;
> output ;
> end ;
> run ;
>
> I don't see the need to do the same for donors. Sophie was just copying
> the donor file so that she could rename AGE to NEWAGE. (The donors were
> not aging.) The other variables didn't change. You were the one that
> introduced new year variable along with the duplication of records from the
> donor file.
>
> On the other hand, when David wakes up, he will probably scream about
> matching donors to the base by AGE and RACESEX and using a different donor
> for each year. (If I knew more I would wonder about the propriety matching
> a person today at, say age 10, with someone who is today 30 so there ages
> will match in 20 years.)
>
> While it is best to avoid macro, the problem Sophie had with her data set
> names is common enough that it deserves a simple solution in macro.
>
> %do y = 1 %to 20;
>
> data base20%sysfunc(putn(&y,z2.));
> set base20%sysfunc(putn(&y-1,z2.));
> ....
>
> Ian Whitlock
> --------------
> Date: Sat, 7 Jul 2007 21:38:36 +0000
> Reply-To: toby dunn <tobydunn@HOTMAIL.COM>
> Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
> From: toby dunn <tobydunn@HOTMAIL.COM>
> Subject: Re: macro problem
> Comments: To: sophiecs@gmail.com
> In-Reply-To: <cb7343d10707071344k50f48b5eh28267d99596a43cb@mail.gmail.com>
> Content-Type: text/plain; format=flowed
> Sophie ,
>
> While I am not totally sure what you bigger goal is, I do know that a macro
> isnt needed, looks like you have a data structure problem. So the solution
> below first resolves the data structure problem and then uses SQL to get
> your final data set.
>
> If you wanted there is one place where a small general looping macro or a
> throw away macro could be used, that being in createing all the data set
> names in the set statement. Personally since you onlu have 20 and I am not
> sure if you will need to rerun with some unknown number of times with more
> or less calls to the 2000 data sets I think you could just as easily get by
> with copy and paste.
>
>
>
> Data Base ( Drop = I ) ;
> Set Base2000 ( In = DS01 )
> Base2000 ( In = DS02 )
> .
> .
> Base2000 ( In = DS20 ) ;
> Array DS ( * ) DS: ;
>
> Do I = 1 To Dim( DS ) ;
> If ( DS( I ) Ne 0 ) Then Leave ;
> End ;
>
> NewAge = Age + I ;
> Year = 2000 + I ;
>
> Run ;
>
>
> Data Donor ;
> Set Donor2000 ( In = DS01 )
> .
> .
> .
> Donor2000 ( In = DS20 ) ;
> Array DS ( * ) DS: ;
>
> Do I = 1 To Dim( DS ) ;
> If ( DS( I ) Ne 0 ) Then Leave ;
> End ;
>
> Year = 2000 + I ;
>
> Run ;
>
>
>
> Proc SQL ;
> Create Table Master ( Drop = NewAge ) As
> Select Base.* , Donor.Var1 , ..... , Donor.VarN
> From Base As Base
> Left Join
> Donor As Donor
> On ( Base.NewAge = Donor.Age )
> And ( Base.RaceSex = Donor.RaceSex )
> And ( Base.Year = Donor.Year )
> And ( RanNum > Rate ) ;
> Quit ;
>
>
>
>
>
>
>
> Toby Dunn
>
> If anything simply cannot go wrong, it will anyway. Murphys Law #2.
>
> The buddy system is essential to your survival; it gives the enemy somebody
> else to shoot at.
> Murphys Law #
>
>
> Tell a man there are 300 billion stars in the universe and he'll believe
> you. Tell him a bench has wet paint on it and he'll have to touch to be
> sure. Murphys Law #9
>
>
>
>
>
>
> From: Sophie Shen <sophiecs@GMAIL.COM>
> Reply-To: sophiecs@gmail.com
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: macro problem
> Date: Sat, 7 Jul 2007 16:44:07 -0400
>
> I have two temp datasets for this program base2000 and donor 2000.
> One problem is the macro wells well until Y resolves to 10 when x
> resolves to 9. The run before y resolves to 10 generates a data set
> base2009 instead of base209.
>
> Can anyone help me out?
>
> Thanks
>
> *Creating 2001-2009 projections;
> %macro whatever;
> %do y = 1 %to 20;
> %let x = %eval(&y - 1);
>
> %if &y <= 9 %then %do;
> data base200&y.;
> set base200&x.;
> agenew=age+&y;
> run;
>
> data donor200&y.;
> set donor200&x.;
> agenew=age; run;
>
> data base200&y.;
> merge donor200&y. base200&y.(in=a);
> by agenew racesex;
> if a;
> drop agenew; run;
>
> data base200&y; set base200&y;
> if rannum le rate then delete;
> run;
> %end;
>
> *create 2010 to 2020 projection*;
> %if &y >= 10 %then %do;
> data base20&y.;
> set base20&x.;
> agenew=age+&y;
> run;
>
> data donor20&y.;
> set donor20&x.;run;
>
> data base20&y.;
> merge donor20&y. base20&y.(in=a);
> by agenew racesex;
> if a;
> drop agenew;run;
>
> data base20&y.; set base20&y.;
> if rannum le rate then delete;
> run;
> %end;
> %end;
>
> %mend whatever;
> %whatever;
> options mprint symbolgen;
>
> _________________________________________________________________
> http://newlivehotmail.com
>
>
>
|