What you want is not clear to me, and given that there are a dozen people who usually respond 10x faster than I can, I'm guessing it's not clear to others. You really should post an example of what the desired end state is. That said, here's my poke at what you want using two approaches that hopefully gets you on the right track. But if I'm way off, my apologies.
data have;
input STUDYNO:32. PID:BEST. Day_1826:DATE9. Day_InitialIW:DATE9. TRICHOT_1YR:BEST12. Personal_consumption_expenditure:BEST12. Month:32. Interval:$5. TimeFrame:$20. ExpenseType:$20. Value:32.;
format PID BEST. Day_1826 DATE9. Day_InitialIW DATE9. TRICHOT_1YR BEST12. Personal_consumption_expenditure BEST12.;
label STUDYNO="Sample size: 55,144,41,185,191, Total:616" PID="SUBJID#" Day_1826="Day1826" Day_InitialIW="IWInitial" TRICHOT_1YR="RA 273, UR 140, RNA 80, Missing 123";
datalines;
2 486 30DEC1992 05OCT1993 1 68.892 1 Month PreResYr House 3164.5029543
2 486 30DEC1992 05OCT1993 1 68.892 1 Month PreResYr Consume 820.0784735
2 486 30DEC1992 05OCT1993 1 68.892 1 Month PreResYr Durable .
2 486 30DEC1992 05OCT1993 1 68.892 1 Month PreResYr Health 332.71026714
2 486 30DEC1992 05OCT1993 1 68.892 1 Month PostResYr House 3075.6491125
2 486 30DEC1992 05OCT1993 1 68.892 1 Month PostResYr Consume 808.7741655
2 486 30DEC1992 05OCT1993 1 68.892 1 Month PostResYr Durable .
2 486 30DEC1992 05OCT1993 1 68.892 1 Month PostResYr Health 316.74626874
;
/* Method 1 */
proc sql;
CREATE TABLE want1 AS
SELECT *,
max((TimeFrame='PostResYr')*value)/max((TimeFrame='PreResYr')*value) AS PostOverPre format percent8.2
FROM have
GROUP BY studyno, pid, expensetype
ORDER BY studyno, pid, expensetype, TimeFrame='PostResYr';
quit;
/* Method 2 */
proc sort data = have;
by studyno pid expensetype descending TimeFrame;
run;
data want2;
retain pre_value;
set have;
by studyno pid expensetype descending TimeFrame;
if first.expensetype then do;
pre_value = value;
PostOverPre = .;
end;
else do;
PostOverPre = value / pre_value;
end;
if last.expensetype then output;
run;
... View more