Prev: Infile error
Next: Proc mianalyze and nonmissing data?
From: inason on 14 Apr 2010 11:47 data have; input subjid day val1 val2 count; cards; 1 -8 34 35 1 1 -7 34 35 2 1 -6 34 35 3 1 -5 . . 4 1 -4 34 35 5 1 -3 . . 6 1 -2 . . 7 1 -1 34 35 8 2 -2 30 31 1 2 -1 30 31 2 3 -8 24 23 1 3 -7 24 23 2 3 -6 24 23 3 3 -5 24 23 4 3 -4 24 23 5 3 -3 24 23 6 3 -2 24 23 7 3 -1 24 23 8 ; run; data want; set have; by subjid; n_mis=max(v1,v2); if first.subjid then flag=0; if n_mis= . then flag+1; run; Im trying to count the number of missing rows (val1 and val2) per subject in the variable flag. however as can be seen in the code this won't happen as flag needs to increment by 1 when ever nmiss = . and restart again for the next subject. Any help would be appreciated. Thanks.
From: Reeza on 14 Apr 2010 12:20 On Apr 14, 8:47 am, inason <iharu...(a)googlemail.com> wrote: > data have; > input subjid day val1 val2 count; > cards; > 1 -8 34 35 1 > 1 -7 34 35 2 > 1 -6 34 35 3 > 1 -5 . . 4 > 1 -4 34 35 5 > 1 -3 . . 6 > 1 -2 . . 7 > 1 -1 34 35 8 > 2 -2 30 31 1 > 2 -1 30 31 2 > 3 -8 24 23 1 > 3 -7 24 23 2 > 3 -6 24 23 3 > 3 -5 24 23 4 > 3 -4 24 23 5 > 3 -3 24 23 6 > 3 -2 24 23 7 > 3 -1 24 23 8 > ; > run; > > data want; > set have; > by subjid; > n_mis=max(v1,v2); > if first.subjid then flag=0; > if n_mis= . then flag+1; > run; > > Im trying to count the number of missing rows (val1 and val2) per > subject in the variable flag. > however as can be seen in the code this won't happen as flag needs to > increment by 1 when ever > nmiss = . and restart again for the next subject. > > Any help would be appreciated. > > Thanks. Use the retain and nmiss functions/statement to keep the flag value between observations. This should count the number of missing values per subject. If you only want the total value, not the running sum add an output line, ie if last.subjid output; data want; set have; by subjid; retain flag 0; if first.subjid then flag=0; flag=flag+nmiss(val1, val2); run; HTH, Reeza
From: inason on 15 Apr 2010 05:43 On Apr 14, 5:20 pm, Reeza <fkhurs...(a)hotmail.com> wrote: > On Apr 14, 8:47 am, inason <iharu...(a)googlemail.com> wrote: > > > > > > > data have; > > input subjid day val1 val2 count; > > cards; > > 1 -8 34 35 1 > > 1 -7 34 35 2 > > 1 -6 34 35 3 > > 1 -5 . . 4 > > 1 -4 34 35 5 > > 1 -3 . . 6 > > 1 -2 . . 7 > > 1 -1 34 35 8 > > 2 -2 30 31 1 > > 2 -1 30 31 2 > > 3 -8 24 23 1 > > 3 -7 24 23 2 > > 3 -6 24 23 3 > > 3 -5 24 23 4 > > 3 -4 24 23 5 > > 3 -3 24 23 6 > > 3 -2 24 23 7 > > 3 -1 24 23 8 > > ; > > run; > > > data want; > > set have; > > by subjid; > > n_mis=max(v1,v2); > > if first.subjid then flag=0; > > if n_mis= . then flag+1; > > run; > > > Im trying to count the number of missing rows (val1 and val2) per > > subject in the variable flag. > > however as can be seen in the code this won't happen as flag needs to > > increment by 1 when ever > > nmiss = . and restart again for the next subject. > > > Any help would be appreciated. > > > Thanks. > > Use the retain and nmiss functions/statement to keep the flag value > between observations. > This should count the number of missing values per subject. If you > only want the total value, not the running sum add an output line, ie > if last.subjid output; > > data want; > set have; > by subjid; > retain flag 0; > if first.subjid then flag=0; > flag=flag+nmiss(val1, val2); > run; > > HTH, > Reeza- Hide quoted text - > > - Show quoted text - Thanks Reeza
|
Pages: 1 Prev: Infile error Next: Proc mianalyze and nonmissing data? |