Not applicable
Posts: 0

# Help with calculating the scores

I have a situation given below. I want to calculate the scores for each row from its Value. If visit '0' is missing for a sample like in case of Sample B, then scores for this sample should be "".I'm just learning SAS. Someone guide me on this.

Sample visit Value Score
A 0 1.2
A 2 0.8
A 3 1.6
B 2 0.3
B 3 1.4
C 0 1.7
C 2 1.9
C 3 0.8

Score= (Value at Visit 0-Value at current visit)/value at visit 0

Can Someone help me with this?

Thanks in Advance! Message was edited by: kireeti
Valued Guide
Posts: 653

## Re: Help with calculating the scores

See if this is close to what you are looking for. There are alternatives depending on data set size and other potential constraints.
[pre]data visitdata;
input Sample \$ visit Value;
datalines;
A 0 1.2
A 2 0.8
A 3 1.6
B 2 0.3
B 3 1.4
C 0 1.7
C 2 1.9
C 3 0.8
run;

proc sort data=visitdata;
by sample visit;
run;

data scores;
set visitdata;
by sample visit;
retain initval .;
if first.sample then do;
if visit = 0 then initval=value;
else initval=.;
end;
*Score= (Value at Visit 0-Value at current visit)/value at visit 0;
if initval ne . then score = (initval - value)/initval;
run;

proc print data=scores;
run;
[/pre]
Not applicable
Posts: 0

## Re: Help with calculating the scores

That seems working. Thanks a lot.
Discussion stats
• 2 replies
• 404 views
• 0 likes
• 2 in conversation