Hi All,
Input | Output | ||||||
EXPOSURE | LOSS | FLAG | EXPOSURE | LOSS | FLAG | ||
0 | 10 | 0 | 0 | 10 | 0 | ||
1 | 10 | 1 | 1 | 10 | 1 | ||
2 | 20 | 0 | 2 | 20 | 0 | ||
3 | 20 | 1 | 3 | 20 | 1 | ||
4 | 30 | 0 | 4 | 30 | 0 | ||
5 | 40 | 0 | 5 | 40 | 0 | ||
6 | 50 | 0 | 6 | 50 | 0 | ||
7 | 50 | 1 | |||||
8 | 50 | 1 | |||||
9 | 50 | 1 | |||||
10 | 50 | 1 |
Above is my test data. We are looking into data from 2014 Actually we are having exposure till 60.
Ex:
For Current month (Aug16): Exposure ranges from 0 to 30
prior month (jul16):Exposure ranges from 0 to 27 ( Current month -3)
pre-prior month (Jun16) : Exposure ranges from 0 to 24 ( prior month -3)
Like this it goes on....
I created a variable lag and flag.
if loss=lag(Loss) then Flag=1; else Flag=0;
I couldn't able to get logic. If I take only Aug16 data exposure is till 60 from row 31 value is duplaicated. I dont want to cosider that duplicated which are from 31 row . How you help how to achive this logic.
data have;
input exposure loss;
cards;
1 0
2 0
3 .1978
4 .1978
5 .1978
6 .2
7 .2
8 .2
9 .2
;
run;
proc sql noprint;
select max(loss) into :maxloss from have;
quit;
data want;
set have;
retain flag 1;
if flag;
if loss = &maxloss then flag = 0;
drop flag;
run;
proc print noobs;
run;
Result:
exposure loss 1 0.0000 2 0.0000 3 0.1978 4 0.1978 5 0.1978 6 0.2000
So, from a series of exposure values, you only want to keep the first one with the highest loss (and discard all later obs with equal loss), and all observations up to that?
Thank you for the reply. I'm trying to keep the value from low to high.
My data looks like this.
Exposure | Loss |
0 | 0 |
1 | 0 |
2 | 0.000001978 |
3 | 0.000001978 |
4 | 0.000001978 |
........... | 0.000053544 |
........... | ............... |
29 | 0.0091486 |
30 | 0.0092539 |
31 | 0.0092539 |
32 | 0.0092539 |
........... | ............... |
........... | ............... |
60 | 0.0092539 |
data have;
input exposure loss;
cards;
1 0
2 0
3 .1978
4 .1978
5 .1978
6 .2
7 .2
8 .2
9 .2
;
run;
proc sql noprint;
select max(loss) into :maxloss from have;
quit;
data want;
set have;
retain flag 1;
if flag;
if loss = &maxloss then flag = 0;
drop flag;
run;
proc print noobs;
run;
Result:
exposure loss 1 0.0000 2 0.0000 3 0.1978 4 0.1978 5 0.1978 6 0.2000
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!
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.