|
|||
|
Hi Bruce,
See if the code below would help you: ***Read the input data; data test; input dx1 $ poa1 $ dx2 $ poa2 $ dx3 $ poa3 $ dx4 $ poa4 $ dx5 $ poa5 $; cards; 133 N 423 Y 422 N 344 Y 231 N 442 N 244 N 224 Y 432 N 222 N 564 Y 344 Y 422 N 952 Y 244 Y ; run; ***Get rid of the DX codes with POA flag="Y"; data test2; set test; array diags(*) dx1-dx5; array flags(*) poa1-poa5; do i=1 to dim(diags); if flags(i)='Y' then do; diags(i)=" "; ***** flags(i)=" "; ***** redundant ; end; end; drop poa1-poa5 i; run; ***Reorder the DX codes so that there are no holes; data test3 (DroP=ToRead ToWrite); set test2; array diag(*) dx1-dx5; ToWrite = 1; DO ToRead = 1 TO DIM(Diag); * DIM(Diag) here is 5 ; IF (Diag(ToRead) NE ' ') THEN DO; Diag(ToWrite) = Diag(ToRead); ToWrite + 1; END; END; * Now all values have been shifted; * Clear remaining original values; DO ToRead = ToWrite TO DIM(Diag); Diag(ToRead) = ' '; END; RUN; *** Both steps above _can_ even be combined to just one step! ; proc print data=test; run; proc print data=test2; *** var dx1 dx2 dx3; *** no, see all variables! ; run; proc print data=test3; *** var dx1 dx2; *** no, see all variables! ; run; Regards - Jim. -- Jim Groeneveld, Netherlands Statistician, SAS consultant home.hccnet.nl/jim.groeneveld On Mon, 24 Sep 2007 10:21:15 -0500, Bruce J <chimanbj@GMAIL.COM> wrote: >Hello again. > >I know how to do this manually, but I would think there's a way to use >arrays to do this more succinctly. I have a table that has diagnosis (DX) >codes, and a present on admission flag (POA)for each diagnosis. What I want >to do is delete the DX codes with a POA set to "Y". Then I want to move all >of the DX codes so that there are no holes in the array. > >For instance, > >DX1=100 >POA=Y >DX2=300 >POA=N >DX3=313 >POA=Y >DX4=421 >POA=Y >DX5=511 >POA=N > >What the output should look like is: > >DX1=300 >DX2=511 > >I can do the basic code below, but I can't wrap my head around the >reordering piece (Monday morning blues, I guess). Can anyone help me? If >it was just the 5 DX codes, I could live with the inefficiencies, but with >30, I need a slick way to do it... > >***Read the input data; >data test; > input dx1 $ poa1 $ dx2 $ poa2 $ dx3 $ poa3 $ dx4 $ poa4 $ dx5 $ poa5 $; >cards; >133 N 423 Y 422 N 344 Y 231 N >442 N 244 N 224 Y 432 N 222 N >564 Y 344 Y 422 N 952 Y 244 Y >; >run; >***Get rid of the DX codes with POA flag="Y"; >data test2; > set test; > array diags(*) dx1-dx5; > array flags(*) poa1-poa5; > do i=1 to dim(diags); > if flags(i)='Y' then do; > diags(i)=" "; > flags(i)=" "; > end; > end; > drop poa1-poa5 i; >run; >***Reorder the DX codes so that there are no holes; >data test3; > set test2; >array diag(*) dx1-dx5; > if dx1=" " then do; > dx1=dx2; > dx2=dx3; > dx3=dx4; > dx4=dx5; > dx5=" "; > end; > if dx1=" " then do; > dx1=dx2; > dx2=dx3; > dx3=dx4; > dx4=" "; > end; > if dx1=" " then do; > dx1=dx2; > dx2=dx3; > dx3=" "; > end; > if dx1=" " then do; > dx1=dx2; > dx2=" "; > end; > if dx2=" " then do; > dx2=dx3; > dx3=dx4; > dx4=dx5; > dx5=" "; > end; > if dx2=" " then do; > dx2=dx3; > dx3=dx4; > dx4=" "; > end; > if dx2=" " then do; > dx2=dx3; > dx3=" "; > end; > ***Continue for all 5 DX codes; >run; > proc print data=test; > run; > proc print data=test2; > var dx1 dx2 dx3; > run; > proc print data=test3; > var dx1 dx2; > run; > >Bruce A Johnson >Data Reporting Specialist, Senior >Thomson Healthcare > >Phone: (847) 424-4249 >Fax: (847) 332-1768 >http://www.thomsonhealthcare.com > >Please note my new email address: >bruce.johnson@thomson.com >Solucient is now part of Thomson Healthcare. |
|
|
||||
|
||||
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Re: creating an array of matching ICD9 codes | John Burton | Newsgroup comp.soft-sys.sas | 0 | 02-25-2009 12:22 AM |
| Re: Reordering Diagnosis Codes | toby dunn | Newsgroup comp.soft-sys.sas | 0 | 09-24-2007 04:23 PM |
| Reordering Diagnosis Codes | Bruce J | Newsgroup comp.soft-sys.sas | 0 | 09-24-2007 03:21 PM |
| Re: Is there a sas code that can clean up ICD-9 codes? | Sigurd Hermansen | Newsgroup comp.soft-sys.sas | 0 | 02-24-2005 04:00 PM |
| Re: Is there a sas code that can clean up ICD-9 codes? | Duck-Hye Yang | Newsgroup comp.soft-sys.sas | 1 | 02-22-2005 09:23 PM |