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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

New Learning Events in April

 

Join us for two new fee-based courses: Administrative Healthcare Data and SAS via Live Web Monday-Thursday, April 24-27 from 1:00 to 4:30 PM ET each day. And Administrative Healthcare Data and SAS: Hands-On Programming Workshop via Live Web on Friday, April 28 from 9:00 AM to 5:00 PM ET.

LEARN MORE

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