BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
2 REPLIES 2
ArtC
Rhodochrosite | Level 12
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]
deleted_user
Not applicable
That seems working. Thanks a lot.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Health and Life Sciences Learning

 

Need courses to help you with SAS Life Sciences Analytics Framework, SAS Health Cohort Builder, or other topics? Check out the Health and Life Sciences learning path for all of the offerings.

LEARN MORE

Discussion stats
  • 2 replies
  • 1157 views
  • 0 likes
  • 2 in conversation