BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SJN
Fluorite | Level 6 SJN
Fluorite | Level 6

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. 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User
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

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

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?

SJN
Fluorite | Level 6 SJN
Fluorite | Level 6

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

 

Kurt_Bremser
Super User
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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 871 views
  • 0 likes
  • 2 in conversation