Hi all,
data have;
input ID Priod Policy_Period amount ;
cards;
1 1 2 100
1 2 2 200
1 3 2 500
1 4 2 200
2 1 3 350
2 2 3 480
2 3 3 10
2 4 3 0
3 1 4 145
3 2 4 150
3 3 4 300
3 4 4 200
;;;;
run;
I want to find the amount for the period before the
policy-period and the amount after the policy period for each ID.
data want;
input ID amount_before amount_after;
cards;
1 100 500
2 480 0
3 300 .
;;;;
run;
data want(keep=ID amount_before amount_after);
call missing(ID, amount_before, amount_after);
do until (last.ID);
set have;
by ID;
if Priod-Policy_Period = -1 then amount_before = amount;
if Priod-Policy_Period = 1 then amount_after = amount;
end;
run;
Result:
ID amount_before amount_after 1 100 500 2 480 0 3 300 .
data want(keep=ID amount_before amount_after);
call missing(ID, amount_before, amount_after);
do until (last.ID);
set have;
by ID;
if Priod-Policy_Period = -1 then amount_before = amount;
if Priod-Policy_Period = 1 then amount_after = amount;
end;
run;
Result:
ID amount_before amount_after 1 100 500 2 480 0 3 300 .
Ok. But Policy_Period is still constant for each id? and in one of the obs, Policy_Period=Period, correct?
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.