Solved
Contributor
Posts: 30

# Logic help...

[ Edited ]

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.

Accepted Solutions
Solution
‎09-29-2016 02:40 AM
Super User
Posts: 10,280

## Re: Logic help...

``````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
```
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

All Replies
Super User
Posts: 10,280

## Re: Logic help...

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?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 30

## Re: Logic help...

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

Solution
‎09-29-2016 02:40 AM
Super User
Posts: 10,280

## Re: Logic help...

``````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
```
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
☑ This topic is solved.