Prev: sample size determination
Next: About sgpanel
From: Sdlentertd on 14 Dec 2009 17:20 I am wondering if I can use an array function to get to the desired results, I am not very familiar with arrays so I appreciate any help I can get. I have this dataset: Record ID1 Code1 Claim1 ID2 Code2 1 123 666 yes 2 128 777 no I need to look at each record if Claim1 = 'YES' then ID2 = ID1 ; Code2 = Code1; etc... until Claim# = 'NO' , Once it hits "NO" then the rest of ID# and Code# will be blank. IF Claim1 = 'NO' then the rest of ID# and Code# will be blank. and there are 10 Claim# that I need to look at. So if Claim1 = yes then populate ID2 and Code2 with Code 1 info; if Claim2 = yes then populate ID3 and Code3 with Code 1 info; if Claim3 = yes then populate ID4 and Code4 with Code 1 (or 2 or3 because they will be the same) info; Record ID1 Code1 Claim1 ID2 Code2 Claim2 ID3 Code2 1 123 666 yes 123 666 no . . 2 128 777 no . . Thank you
From: "Schwarz, Barry A" on 14 Dec 2009 18:17 Yes you can but you are going to have to be more specific. If Claim1 and Claim2 are both YES, do you really want ID2 changed to equal ID1 or are you guaranteed that they will already be equal? Is it possible for Claim2 to be NO but Claim3 to be YES? You can define an array for each variable type with a statement of the form ARRAY claim_array(*) $ claim1-claim10; You can then loop through the variables with a do loop of the form DO i = 1 to DIM(claim_array); IF claim_array(i) = "YES" THEN ... END; -----Original Message----- From: SAS(r) Discussion [mailto:SAS-L(a)LISTSERV.UGA.EDU] On Behalf Of Sdlentertd Sent: Monday, December 14, 2009 2:20 PM To: SAS-L(a)LISTSERV.UGA.EDU Subject: Array use? I am wondering if I can use an array function to get to the desired results, I am not very familiar with arrays so I appreciate any help I can get. I have this dataset: Record ID1 Code1 Claim1 ID2 Code2 1 123 666 yes 2 128 777 no I need to look at each record if Claim1 = 'YES' then ID2 = ID1 ; Code2 = Code1; etc... until Claim# = 'NO' , Once it hits "NO" then the rest of ID# and Code# will be blank. IF Claim1 = 'NO' then the rest of ID# and Code# will be blank. and there are 10 Claim# that I need to look at. So if Claim1 = yes then populate ID2 and Code2 with Code 1 info; if Claim2 = yes then populate ID3 and Code3 with Code 1 info; if Claim3 = yes then populate ID4 and Code4 with Code 1 (or 2 or3 because they will be the same) info; Record ID1 Code1 Claim1 ID2 Code2 Claim2 ID3 Code2 1 123 666 yes 123 666 no . . 2 128 777 no . .
From: Gerhard Hellriegel on 15 Dec 2009 13:35 try something like that: data test; set test; length claim3-claim10 $5 code1 - code10 8 id2 - id10 8; array a_claim(*) claim1-claim10; array a_id(*) id1-id10; array a_code(*) code1-code10; do i=1 to 10 until(compress(upcase(a_claim(i))) = "NO"); a_id(i)=a_id(1); a_code(i)=a_code(1); end; run; you want blanks in CODEn and IDn ? Define them as char for that. Gerhard On Mon, 14 Dec 2009 14:20:06 -0800, Sdlentertd <sdlentertd(a)GMAIL.COM> wrote: >I am wondering if I can use an array function to get to the desired >results, I am not very familiar with arrays so I appreciate any help I >can get. >I have this dataset: >Record ID1 Code1 Claim1 ID2 Code2 >1 123 666 yes >2 128 777 no >I need to look at each record if Claim1 = 'YES' then ID2 = ID1 ; Code2 >= Code1; etc... until Claim# = 'NO' , Once it hits "NO" then the >rest of ID# and Code# will be blank. >IF Claim1 = 'NO' then the rest of ID# and Code# will be blank. > >and there are 10 Claim# that I need to look at. >So if Claim1 = yes then populate ID2 and Code2 with Code 1 info; >if Claim2 = yes then populate ID3 and Code3 with Code 1 info; >if Claim3 = yes then populate ID4 and Code4 with Code 1 (or 2 or3 >because they will be the same) info; > >Record ID1 Code1 Claim1 ID2 Code2 Claim2 ID3 Code2 >1 123 666 yes 123 666 >no . . >2 128 777 no . . > > >Thank you
From: Sdlentertd on 15 Dec 2009 14:56 On Dec 15, 11:35 am, gerhard.hellrie...(a)T-ONLINE.DE (Gerhard Hellriegel) wrote: > try something like that: > > data test; > set test; > length claim3-claim10 $5 > code1 - code10 8 > id2 - id10 8; > array a_claim(*) claim1-claim10; > array a_id(*) id1-id10; > array a_code(*) code1-code10; > do i=1 to 10 until(compress(upcase(a_claim(i))) = "NO"); > a_id(i)=a_id(1); > a_code(i)=a_code(1); > end; > run; > > you want blanks in CODEn and IDn ? > Define them as char for that. > Gerhard > > On Mon, 14 Dec 2009 14:20:06 -0800, Sdlentertd <sdlente...(a)GMAIL.COM> > wrote: > > > > >I am wondering if I can use an array function to get to the desired > >results, I am not very familiar with arrays so I appreciate any help I > >can get. > >I have this dataset: > >Record ID1 Code1 Claim1 ID2 Code2 > >1 123 666 yes > >2 128 777 no > >I need to look at each record if Claim1 = 'YES' then ID2 = ID1 ; Code2 > >= Code1; etc... until Claim# = 'NO' , Once it hits "NO" then the > >rest of ID# and Code# will be blank. > >IF Claim1 = 'NO' then the rest of ID# and Code# will be blank. > > >and there are 10 Claim# that I need to look at. > >So if Claim1 = yes then populate ID2 and Code2 with Code 1 info; > >if Claim2 = yes then populate ID3 and Code3 with Code 1 info; > >if Claim3 = yes then populate ID4 and Code4 with Code 1 (or 2 or3 > >because they will be the same) info; > > >Record ID1 Code1 Claim1 ID2 Code2 Claim2 ID3 Code2 > >1 123 666 yes 123 666 > >no . . > >2 128 777 no . . > > >Thank you- Hide quoted text - > > - Show quoted text - This is great and works, but what if one of the fields that has to be in array is in different format than the other, for example: ID1 is character but another field is Date which is Date9. and another field Price which is numeric.... How do i put them all in one array? or how can I do two seperate arrays for one dataset? Thank you
From: "Schwarz, Barry A" on 16 Dec 2009 14:29
Arrays are not related to datasets but to variables. It is perfectly acceptable to have multiple arrays dealing with different variables, such as ARRAY a_array(*) $ var_a1-var_a9; ARRAY b_array(*) var_b1-var_b23; Different arrays can have different dimensions (9 vs 23 in the example) and types (character vs numeric). Date9. is a format which has nothing to do with arrays. It only affects how a numeric variable is converted to a character string in the PUT function or the PUT statement. (Date and time variables are just normal numeric variables with special meanings attached to the values.) -----Original Message----- From: SAS(r) Discussion [mailto:SAS-L(a)LISTSERV.UGA.EDU] On Behalf Of Sdlentertd Sent: Tuesday, December 15, 2009 11:57 AM To: SAS-L(a)LISTSERV.UGA.EDU Subject: Re: Array use? <snip> This is great and works, but what if one of the fields that has to be in array is in different format than the other, for example: ID1 is character but another field is Date which is Date9. and another field Price which is numeric.... How do i put them all in one array? or how can I do two seperate arrays for one dataset? Thank you |