From: Mike Zdeb on
hi ... I think this does what you intended to do with your code

I used a DOW and also took advantage of you wanting to calculate a sum
when PVAL = 1 ... I incorporated that into the SUM statements
(no addition if PVAL = 0, add a value if PVAL = 1)

the values of C and MHDENT look OK to me

comments: your data had too few values in the 3rd row, so I added a missing value for MHDT;
why do you have two variables for the same piece of information, side=1 is side_t=LEFT and side=2 is side_=RIGHT

how about one variable and a format, side, and a format




data x;
input side_t : $5. PATID : $7. VRD sampno PVAL mhdt side;
datalines;
LEFT 01S0018 0 129 0 -0.493 1
LEFT 01S0019 0 137 1 6.44 1
RIGHT 01S0019 0 144 0 . 2
RIGHT 01S0024 0 183 1 1.367 2
LEFT 01S0024 1 402 0 5.53 1
RIGHT 01S0024 1 405 1 19.817 2
LEFT 01S0028 0 211 1 1.342 1
LEFT 01S0028 0 212 1 1.032 1
LEFT 01S0028 1 436 1 1.14 1
RIGHT 01S0028 1 437 0 2.876 2
RIGHT 01S0028 1 440 1 4.019 2
;
run;

proc sort data=x;
by patid vrd side;
run;

data y;
do until (last.side);
set x;
by patid vrd side;
c = sum(c,(1*pval));
mhdent = sum(mhdent,(mhdt*pval));
end;
keep patid vrd side c mhdent;
run;

proc print data=y;
var patid vrd side c mhdent;
run;


Obs PATID VRD side c mhdent
1 01S0018 0 1 0 0.000
2 01S0019 0 1 1 6.440
3 01S0019 0 2 0 .
4 01S0024 0 2 1 1.367
5 01S0024 1 1 0 0.000
6 01S0024 1 2 1 19.817
7 01S0028 0 1 2 2.374
8 01S0028 1 1 1 1.140
9 01S0028 1 2 1 4.019


--
Mike Zdeb
U(a)Albany School of Public Health
One University Place
Rensselaer, New York 12144-3456
P/518-402-6479 F/630-604-1475

> hi to All,
>
> I have data like
>
> side_t PATID VRD sampno PVAL mhdt side
> LEFT 01S0018 0 129 0 -0.493 1
> LEFT 01S0018 1 370 1 1.975 1
> LEFT 01S0019 0 137 1 6.44 1
> RIGHT 01S0019 0 144 0 2
> RIGHT 01S0024 0 183 1 1.367 2
> LEFT 01S0024 1 402 0 5.53 1
> RIGHT 01S0024 1 405 1 19.817 2
> LEFT 01S0028 0 211 1 1.342 1
> LEFT 01S0028 0 212 1 1.032 1
> LEFT 01S0028 1 436 1 1.14 1
> RIGHT 01S0028 1 437 0 2.876 2
> RIGHT 01S0028 1 440 1 4.019 2
>
> I need output like
>
> if pval=1 then only I have to calculate sum of mhdt based on left side
> samples and vorder wise
>
>
>
> if pval=0 its not include in sum and count variable
>
> can you please check this code
>
>
> data ncontac2(drop=sampleno);
> set ncontac1;
> retain mhdent c;
> by patid vorder side;
> if pval ne 0 then do;
> if first.side then do;mhdent=.;c=.;end;
> if mhdt ne . then do;
> mhdent=sum(mhdent, mhdt);
> c+1;
> end;
> end;
> else do;
> mhdent=mhdt;
> end;
> if last.side ;
> run;
>
> as per this code,im getting count for subject 01S0028 right side count is
> 3
> but i want only 1. can you please check and let me know
>
> Thanks,
> Hymad
>