This might be a good situation for a merge statement, as in:
data sv_raw;
input PT_ID $ Visit Res ;
datalines;
1 1 20
1 2 40
1 3 30
2 1 30
2 2 40
2 3 50
run;
data want;
merge sv_raw (keep=pt_id visit res rename=(res=base) where=(visit=1))
sv_raw;
by pt_id;
run;
This program assumes that:
- The data are sorted by PT_ID
- Each PT_ID has one record with visit=1.
The program is a 1-to-many match merge based on PT_ID.
if matches a subset of SV_RAW (namely only observations with visit=1) will all of SV_RAW, matched on PT_ID.
But both the subset and the complete set have a variable named RES, so to avoid a "collision" I rename the RES in the subset to BASE.
You might note there would be a collision of VISIT also. But when there is a collision, it will be the latter instance of visit (from the complete set) that overwrites the value from the earlier instance (the visit=1 subset). In other words, the order of the two objects of the MERGE statement matters.
This order would be wrong
merge have
have (keep=pt_id visit res rename(res=base) where=(visit=1));
because the value of visit=1 would overwrite all the visit values from the other records.