LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (January 2010, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 19 Jan 2010 22:11:40 +0100
Reply-To:     Daniel Fernández <fdezdan@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Daniel Fernández <fdezdan@GMAIL.COM>
Subject:      Re: problem with automatic categorization of variables
Comments: To: Yu Zhang <zhangyu05@gmail.com>
In-Reply-To:  <445d9dbe1001191144x52de4363n926f5f952e8d6349@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

thanx Yu, I was developing the code and I forgot to elimitate the %put.

Daniel Fernandez

El día 19 de enero de 2010 20:44, Yu Zhang <zhangyu05@gmail.com> escribió: > change the %put %pod(masa) to %pod(masa). it should work as intended. > > HTH > > Yu > > 2010/1/19 Daniel Fernández <fdezdan@gmail.com> >> >> I have coded a dummy dataset and call the following macro: >> >> data dummy; >> do masa=13 to 70; >> output; >> end; >> run; >> >> %macro pod(d); >> %let grup=2; >> %do i=16 %to 58 %by 2; >> %let j=%eval(&i+2); >> if &i < &d <= &j then A=&grup; >> %let grup=%eval(&grup+1); >> %end; >> %MEND pod; >> >> data test; >> set dummy; >> if masa <= 16 then a = 1; >> %put %pod(masa); >> if masa >60 then a = 24; >> put masa a; >> run; >> >> Unfortunatly, I don´t know why the second condition doesn´t satisfy >> (when if 16 < masa<= 18 then A=2): >> >> >> 13 1 >> 14 1 >> 15 1 >> 16 1 >> 17 . >> 18 . >> 19 3 >> 20 3 >> 21 4 >> 22 4 >> 23 5 >> 24 5 >> 25 6 >> 26 6 >> 27 7 >> 28 7 >> 29 8 >> 30 8 >> 31 9 >> 32 9 >> 33 10 >> 34 10 >> 35 11 >> 36 11 >> 37 12 >> 38 12 >> 39 13 >> 40 13 >> 41 14 >> 42 14 >> 43 15 >> 44 15 >> 45 16 >> 46 16 >> 47 17 >> 48 17 >> 49 18 >> 50 18 >> 51 19 >> 52 19 >> 53 20 >> 54 20 >> 55 21 >> 56 21 >> 57 22 >> 58 22 >> 59 23 >> 60 23 >> 61 24 >> 62 24 >> 63 24 >> 64 24 >> 65 24 >> 66 24 >> 67 24 >> 68 24 >> 69 24 >> 70 24 >> >> >> >> Daniel Fernandez >> >> >> >> >> >> >> 2010/1/19 Mark Miller <mdhmiller@gmail.com>: >> > Emil, >> > >> > Does the following satisfy your desire for more compact code ? >> > >> > a =min(24,max(1,1+ceil((masa-15)/2))) ; >> > >> > ... Mark Miller >> > >> > >> > >> > On Tue, Jan 19, 2010 at 7:57 AM, Emil <remilah@gmail.com> wrote: >> > >> >> On 19 Sty, 13:03, Tom Abernathy <tom.aberna...@gmail.com> wrote: >> >> > Emil - >> >> > What are you trying to get the new variable B to contain? >> >> > It almost looks like you are trying to program the MOD function. >> >> > If you want to make 2 codes then use B=MOD(D,2) and you will get >> >> > 0,1,0,1,1,.... >> >> > If you want to make 3 codes then use B=MOD(D,3) ... >> >> > I am not sure how N comes into it. >> >> > - Tom >> >> >> >> >> >> I would like to make thise code lighter >> >> >> >> >> >> data n5; >> >> set zb.all; >> >> if masa <= 16 then a = 1; >> >> if 16 < masa <= 18 then a= 2; >> >> if 18 < masa <= 20 then a= 3; >> >> if 20 < masa <= 22 then a= 4; >> >> if 22 < masa <= 24 then a= 5; >> >> if 24 < masa <= 26 then a= 6; >> >> if 26 < masa <= 28 then a= 7; >> >> if 28 < masa <= 30 then a= 8; >> >> if 30 < masa <= 32 then a= 9; >> >> if 32 < masa <= 34 then a= 10; >> >> if 34 < masa <= 36 then a= 11; >> >> if 36 < masa <= 38 then a= 12; >> >> if 38 < masa <= 40 then a= 13; >> >> if 40 < masa <= 42 then a= 14; >> >> if 42 < masa <= 44 then a= 15; >> >> if 44 < masa <= 46 then a= 16; >> >> if 46 < masa <= 48 then a= 17; >> >> if 48 < masa <= 50 then a= 18; >> >> if 50 < masa <= 52 then a= 19; >> >> if 52 < masa <= 54 then a= 20; >> >> if 54 < masa <= 56 then a= 21; >> >> if 56 < masa <= 58 then a= 22; >> >> if 58 < masa <= 60 then a= 23; >> >> if masa >60 then a = 24; >> >> run; >> >> >> >> >> >> >> >> >> >> > >> >> > On Jan 19, 6:34 am, Emil <remi...@gmail.com> wrote: >> >> > >> >> > > On 18 Sty, 16:30, RolandRB <rolandbe...@hotmail.com> wrote: >> >> > >> >> > > > On 18 Jan., 14:26, Emil <remi...@gmail.com> wrote: >> >> > >> >> > > > > hi I need to categorize variable (let it be 'b'). I wrote this >> >> > > > > code >> >> > > > > and i don't know what is wrong :( >> >> > >> >> > > > > data z1; >> >> > > > > input p $ d t $ ; >> >> > > > > cards; >> >> > > > > 3 1 a1 >> >> > > > > 3 5 a3 >> >> > > > > 3 7 a8 >> >> > > > > 3 9 a5 >> >> > > > > 3 6 g2 >> >> > > > > 3 . t1 >> >> > > > > . 0 . >> >> > > > > . . . >> >> > > > > 1 4 g2 >> >> > > > > 2 1 f1 >> >> > > > > 2 4 1 >> >> > > > > run; >> >> > > > > ----------------------------------------------- >> >> > > > > and my macro >> >> > > > > ---------------------------------------------- >> >> > > > > I would have 1 category (variable 'b') every 2 units (variable >> >> 'd') >> >> > > > > ======================================= >> >> > > > > %macro pod( n=, l=); >> >> > > > > data new; >> >> > > > > set z1; >> >> > > > > %do i=1 %to &n %by 2; >> >> > > > > %do j=&i+2 %to &n; >> >> > > > > %do k=1 %to &l; >> >> > > > > if &i < d < &j then b=&k; >> >> > > > > %end; >> >> > > > > %end; >> >> > > > > %end; >> >> > > > > run; >> >> > > > > %MEND pod; >> >> > >> >> > > > Get rid of the % sign in front of the words "do", "to", "by" and >> >> "end" >> >> > > > and it might work. >> >> > >> >> > > it dosn't :(- Hide quoted text - >> >> > >> >> > > - Show quoted text - >> >> >> > > >


Back to: Top of message | Previous page | Main SAS-L page