Solved
Contributor
Posts: 20

# How to use maxif function in sas eguide

Dear all,

I need you all guys help about e-guide. I have the dataset as below;

contract          CUS_ID           MAX_day_passed_due      Contract_Date

1                    AAA                         10                                   1Jan2011

2                    AAA                         20                                   3Jan2012

3                    BBB                         30                                   4Jan2012

4                    CCC                        30                                   5Jan2012

5                    BBB                         40                                   10Feb2012

6                    BBB                         30                                   12Jan2014

I want to know the maximum day passed due of every customer  of their previous contracts like this

contract          CUS_ID           MAX_day_passed_due      Contract_Date          Maximum_Day_Pass_Due

1                    AAA                         10                                   1Jan2011          .

2                    AAA                         20                                   3Jan2012          10

3                    BBB                         30                                   4Jan2012          .

4                    CCC                        30                                   5Jan2012          .

5                    BBB                         40                                   10Feb2012        30

6                    BBB                         30                                   12Jan2014        40

i really have no idea how to find out the answer. Really need you all guys help

Best regards,

Ros

Accepted Solutions
Solution
‎10-22-2014 01:41 AM
Super Contributor
Posts: 490

## Re: How to use maxif function in sas eguide

data have ;

input contract          CUS_ID    \$ 3.       MAX_day_passed_due      Contract_Date date9.;

cards;

1 AAA 10 1Jan2011

2 AAA 20 3Jan2012

3 BBB 30 4Jan2012

4 CCC 30 5Jan2012

5 BBB 40 10Feb2012

6 BBB 30 12Jan2014

;

run;

proc sort data=have;

by cus_id Contract_Date;

run;

data need ;

set have;

by cus_id;

retain  Maximum_Day_Pass_Due .;

If first.cus_id then do ;

Maximum_Day_Pass_Due=.;

End;

if  Maximum_Day_Pass_Due < MAX_day_passed_due then do;

output;

Maximum_Day_Pass_Due=MAX_day_passed_due;

End;

Else do;

output;

End;

run;

proc sort data=need;

by Contract_Date;

run;

All Replies
Solution
‎10-22-2014 01:41 AM
Super Contributor
Posts: 490

## Re: How to use maxif function in sas eguide

data have ;

input contract          CUS_ID    \$ 3.       MAX_day_passed_due      Contract_Date date9.;

cards;

1 AAA 10 1Jan2011

2 AAA 20 3Jan2012

3 BBB 30 4Jan2012

4 CCC 30 5Jan2012

5 BBB 40 10Feb2012

6 BBB 30 12Jan2014

;

run;

proc sort data=have;

by cus_id Contract_Date;

run;

data need ;

set have;

by cus_id;

retain  Maximum_Day_Pass_Due .;

If first.cus_id then do ;

Maximum_Day_Pass_Due=.;

End;

if  Maximum_Day_Pass_Due < MAX_day_passed_due then do;

output;

Maximum_Day_Pass_Due=MAX_day_passed_due;

End;

Else do;

output;

End;

run;

proc sort data=need;

by Contract_Date;

run;

Super Contributor
Posts: 490

## Re: How to use maxif function in sas eguide

If you have special question about the Enterprise Guide, you can post your question @

Super User
Posts: 10,778

## Re: How to use maxif function in sas eguide

```data have ;
input contract          CUS_ID    \$ 3.       MAX_day_passed_due      Contract_Date date9.;
cards;
1 AAA 10 1Jan2011
2 AAA 20 3Jan2012
3 BBB 30 4Jan2012
4 CCC 30 5Jan2012
5 BBB 40 10Feb2012
6 BBB 30 12Jan2014
;
run;

proc sort data=have;
by cus_id Contract_Date;
run;

data need ;
set have;
by cus_id;
retain Maximum_Day_Pass_Due .;
Maximum_Day_Pass_Due=max(Maximum_Day_Pass_Due,lag(MAX_day_passed_due)) ;
If first.cus_id then Maximum_Day_Pass_Due=.;
run;

proc sort data=need;
by Contract_Date;
run;

```

Xia Keshan

🔒 This topic is solved and locked.