```Date: Fri, 18 Jul 2008 13:08:58 -0500 Reply-To: "data _null_," Sender: "SAS(r) Discussion" From: "data _null_," Subject: Re: a data manipulation question Comments: To: sas biology In-Reply-To: <95b101340807181032q778a58c8yd2c1a24a278185f1@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 You need a way to evaluate the flags that have been tallied over all the visits simultaneously. Then you can compute the new flag. I chose the popular double "do until last." construct. However you might find it convenient to create a format/informat so that you can look up the FLAG for any subject whenever you need to know. Here is a data step that produces the desired output based on your input data. I assume that your "flag2" logic which does not include all possibilities is suited to your data. I think your need data was incorrect for subject 8. data test; input subjid visit flag1 @@; cards; 1 1 1 1 2 1 1 2 2 2 1 2 2 2 3 3 1 1 3 1 3 3 2 3 4 1 1 4 2 1 4 2 4 5 1 2 5 2 2 5 2 4 6 1 3 6 2 3 6 2 4 7 1 1 7 2 1 8 1 2 8 2 2 8 1 3 9 2 3 ;;;; run; options missing=' '; data test; array _f[4]; *drop _f: flag; do until(last.subjid); set test; by subjid; _f[flag1] = flag1; end; flag = input(cats(of _f[*]),f8.); if flag=1 then flag2=1; else if flag=2 then flag2=2; else if flag=3 then flag2=3; else if flag=12 then flag2=4; else if flag=23 then flag2=5; else if flag=13 then flag2=6; else if flag=14 then flag2=7; else if flag=24 then flag2=8; else if flag=34 then flag2=9; do until(last.subjid); set test; by subjid; output; end; run; proc print; run; On 7/18/08, sas biology wrote: > Hi All, > > Can anyone help me solve the following problem? > > I have the following data > > * > > data* test; > > input subject visit flag1 ; > > cards; > > 1 1 1 > > 1 2 1 > > 1 2 2 > > 2 1 2 > > 2 2 3 > > 3 1 1 > > 3 1 3 > > 3 2 3 > > 4 1 1 > > 4 2 1 > > 4 2 4 > > 5 1 2 > > 5 2 2 > > 5 2 4 > > 6 1 3 > > 6 2 3 > > 6 2 4 > > 7 1 1 > > 7 2 1 > > 8 1 2 > > 8 2 2 > > 8 1 3 > > 9 2 3 > > ; > * > > run*; > > > > I need to process it using the following logic > > > > **if flag1= 1 only then flag2 =1 > > else if flag1= 2 only then flag2= 2 > > else if flag1=3 only then flag2=3 > > else if flag1 in (1 2) then flag2=4 > > else if flag1 in (2 3) then flag2=5 > > else if flag1 in (1 3) then flag2=6 > > else if flag1 in (1 4) then flag2=7 > > else if flag1 in (2 4) then flag2=8 > > else if flag1 in (3 4) then flag2=9; > > and my output data should look like this. > * > > 1* *1* *1* *4 > > 1* *2* *1* *4 > > 1* *2* *2* *4 > > 2* *1* *2* *5 > > 2* *2* *3* *5 > > 3* *1* *1* *6 > > 3* *1* *3* *6 > > 3* *2* *3* *6 > > 4* *1* *1* *7 > > 4* *2* *1* *7 > > 4* *2* *4* *7 > > 5* *1* *2* *8 > > 5* *2* *2* *8 > > 5* *2* *4* *8 > > 6* *1* *3* *9 > > 6* *2* *3* *9 > > 6* *2* *4* *9 > > 7* *1* *1* *1 > > 7* *2* *1* *1 > > 8* *1* *2* *2* * > > 8* *2* *2* *2 > > 8* *1* *3* *3 > > 9* *2* *3* *3* > > ** > > *Thanks in Advance.* > > *SB > * > ```

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