From: Al on 17 Mar 2010 15:36 All: I am supposed to create a variable BSLN(Baseline) based on the following conditions ,if days < 0 and if lbtest = A or B then BSLN = Average of all values(within lbtest) collected before day 0 .. and for lb test = C , the baseline should be the value which is closet to day 0 Any suggestions are greatly appreciated Thanks in advance Al. patno lbtest days result 1 A -12 12 1 A -13 22 1 A -11 11 1 B -3 12 1 B -4 13 1 C -3 11 1 C -4 12 2 A -3 16 2 A -4 12 2 B -6 10 2 B -9 12 2 B -5 22 2 C -1 10
From: data _null_; on 17 Mar 2010 16:20 On Mar 17, 2:36 pm, Al <ali6...(a)gmail.com> wrote: > All: > > I am supposed to create a variable BSLN(Baseline) based on the > following conditions ,if days < 0 and if lbtest = A or B then BSLN = > Average of all values(within lbtest) collected before day 0 .. and > for lb test = C , the baseline should be the value which is closet to > day 0 > > Any suggestions are greatly appreciated > > Thanks in advance > Al. > > patno lbtest days result > 1 A -12 12 > 1 A -13 22 > 1 A -11 11 > 1 B -3 12 > 1 B -4 13 > 1 C -3 11 > 1 C -4 12 > 2 A -3 16 > 2 A -4 12 > 2 B -6 10 > 2 B -9 12 > 2 B -5 22 > 2 C -1 10 I would use PROC SUMMARY. Two methods are shown the result is the same not much difference in the methods. data test; input patno :$1. lbtest :$1. days result; cards; 1 A -12 12 1 A -13 22 1 A -11 11 1 B -3 12 1 B -4 13 1 C -3 11 1 C -4 12 2 A -3 16 2 A -4 12 2 B -6 10 2 B -9 12 2 B -5 22 2 C -1 10 ;;;; run; proc print; run; Method1: proc summary nway data=test; where days lt 0; class patno lbtest; output out=bsln mean(result)=AB idgroup(max(days) out(result)=C); run; data bsln; set bsln; if lbtest in('A' 'B') then bsln = ab; else bsln = c; run; proc print; run; Method2: proc summary nway data=test; where days lt 0; class patno lbtest; output out=bsln1(drop=_: where=(lbtest in('A' 'B'))) mean(result)=bsln; output out=bsln2(drop=_: where=(lbtest eq 'C')) idgroup(max(days) out(result)=bsln); run; data bsln; set bsln1 bsln2; by patno lbtest; run;
From: Al on 17 Mar 2010 18:58 On Mar 17, 3:20 pm, "data _null_;" <datan...(a)gmail.com> wrote: > On Mar 17, 2:36 pm, Al <ali6...(a)gmail.com> wrote: > > > > > > > All: > > > I am supposed to create a variable BSLN(Baseline) based on the > > following conditions ,if days < 0 and if lbtest = A or B then BSLN = > > Average of all values(within lbtest) collected before day 0 .. and > > for lb test = C , the baseline should be the value which is closet to > > day 0 > > > Any suggestions are greatly appreciated > > > Thanks in advance > > Al. > > > patno lbtest days result > > 1 A -12 12 > > 1 A -13 22 > > 1 A -11 11 > > 1 B -3 12 > > 1 B -4 13 > > 1 C -3 11 > > 1 C -4 12 > > 2 A -3 16 > > 2 A -4 12 > > 2 B -6 10 > > 2 B -9 12 > > 2 B -5 22 > > 2 C -1 10 > > I would use PROC SUMMARY. Two methods are shown the result is the > same not much difference in the methods. > > data test; > input patno :$1. lbtest :$1. days result; > cards; > 1 A -12 12 > 1 A -13 22 > 1 A -11 11 > 1 B -3 12 > 1 B -4 13 > 1 C -3 11 > 1 C -4 12 > 2 A -3 16 > 2 A -4 12 > 2 B -6 10 > 2 B -9 12 > 2 B -5 22 > 2 C -1 10 > ;;;; > run; > proc print; > run; > Method1: > proc summary nway data=test; > where days lt 0; > class patno lbtest; > output out=bsln > mean(result)=AB > idgroup(max(days) out(result)=C); > run; > data bsln; > set bsln; > if lbtest in('A' 'B') > then bsln = ab; > else bsln = c; > run; > proc print; > run; > Method2: > proc summary nway data=test; > where days lt 0; > class patno lbtest; > output out=bsln1(drop=_: where=(lbtest in('A' 'B'))) > mean(result)=bsln; > output out=bsln2(drop=_: where=(lbtest eq 'C')) idgroup(max(days) > out(result)=bsln); > run; > data bsln; > set bsln1 bsln2; > by patno lbtest; > run;- Hide quoted text - > > - Show quoted text - I love the solution ... i have tried to do it in datastep with retain. it worked ..but if there is any missing value in result field .. my code does not work ..can anyone help thanks in advance
From: Steve James on 18 Mar 2010 12:04 What may be messing your data step code is when you try to add two numbers using a '+' you end up with a missing value if one of the values are missing. However if you use the SUM function it won't. In the code below Z ends up with a missing value but W does not. 1 data temp ; 2 x=1 ; 3 y = . ; 4 z = x+y ; 5 w = sum(x,y) ; 6 put _all_ ; 7 run ; x=1 y=. z=. w=1 _ERROR_=0 _N_=1 NOTE: Missing values were generated as a result of performing an operation on missing values. Each place is given by: (Number of times) at (Line):(Column). 1 at 4:6 NOTE: The data set WORK.TEMP has 1 observations and 4 variables. NOTE: DATA statement used (Total process time): real time 0.20 seconds cpu time 0.01 seconds Steve On Mar 17, 6:58 pm, Al <ali6...(a)gmail.com> wrote: > On Mar 17, 3:20 pm, "data _null_;" <datan...(a)gmail.com> wrote: > > > > > > > On Mar 17, 2:36 pm, Al <ali6...(a)gmail.com> wrote: > > > > All: > > > > I am supposed to create a variable BSLN(Baseline) based on the > > > following conditions ,if days < 0 and if lbtest = A or B then BSLN = > > > Average of all values(within lbtest) collected before day 0 .. and > > > for lb test = C , the baseline should be the value which is closet to > > > day 0 > > > > Any suggestions are greatly appreciated > > > > Thanks in advance > > > Al. > > > > patno lbtest days result > > > 1 A -12 12 > > > 1 A -13 22 > > > 1 A -11 11 > > > 1 B -3 12 > > > 1 B -4 13 > > > 1 C -3 11 > > > 1 C -4 12 > > > 2 A -3 16 > > > 2 A -4 12 > > > 2 B -6 10 > > > 2 B -9 12 > > > 2 B -5 22 > > > 2 C -1 10 > > > I would use PROC SUMMARY. Two methods are shown the result is the > > same not much difference in the methods. > > > data test; > > input patno :$1. lbtest :$1. days result; > > cards; > > 1 A -12 12 > > 1 A -13 22 > > 1 A -11 11 > > 1 B -3 12 > > 1 B -4 13 > > 1 C -3 11 > > 1 C -4 12 > > 2 A -3 16 > > 2 A -4 12 > > 2 B -6 10 > > 2 B -9 12 > > 2 B -5 22 > > 2 C -1 10 > > ;;;; > > run; > > proc print; > > run; > > Method1: > > proc summary nway data=test; > > where days lt 0; > > class patno lbtest; > > output out=bsln > > mean(result)=AB > > idgroup(max(days) out(result)=C); > > run; > > data bsln; > > set bsln; > > if lbtest in('A' 'B') > > then bsln = ab; > > else bsln = c; > > run; > > proc print; > > run; > > Method2: > > proc summary nway data=test; > > where days lt 0; > > class patno lbtest; > > output out=bsln1(drop=_: where=(lbtest in('A' 'B'))) > > mean(result)=bsln; > > output out=bsln2(drop=_: where=(lbtest eq 'C')) idgroup(max(days) > > out(result)=bsln); > > run; > > data bsln; > > set bsln1 bsln2; > > by patno lbtest; > > run;- Hide quoted text - > > > - Show quoted text - > > I love the solution ... i have tried to do it in datastep with retain. > it worked ..but if there is any missing value in result field .. my > code does not work ..can anyone help > thanks in advance- Hide quoted text - > > - Show quoted text -
|
Pages: 1 Prev: SAS Macro - Is there a way to use an if statement to set two variables? Next: Can i merge |