## highest value

Solved
Occasional Contributor
Posts: 13

# highest value

Hi,

I have a data set and i want to sellect only highest Profit from attached file,

Ex:-  Highest profit from 2009 2010 2011 2012.

the data set have 9000 Observation from that i have sorted profit by if statment and i got folling record.

if profit = > 15000;

but i need only one one Highest profit from each year.

Accepted Solutions
Solution
‎06-28-2016 09:05 AM
Valued Guide
Posts: 534

## Re: highest value

Hi @Prashant_Ph,

Not entirely certain what you want. So I take a stab guessing you want the max profit per year. You can use proc means for that. Assign the YEAR. format to the date to specifiy the required aggregation level of year.

data profit;
infile cards dlm='#';
length type \$200;
format pdate date9.;
input pdate : mmddyy10. type \$ profit;
cards;
1/6/2009#Delivery Truck#16413.8242
1/7/2009#Regular Air#18527.1684
1/22/2009#Delivery Truck#17506.2518
2/15/2009#Delivery Truck#15227.6924
3/21/2009#Regular Air#34399.4625
8/21/2009#Delivery Truck#15688.9425
1/3/2010#Delivery Truck#18052.4284
10/20/2010#Delivery Truck#15904.1736
5/22/2011#Delivery Truck#19200.9844
11/19/2011#Delivery Truck#18598.6608
12/21/2011#Delivery Truck#19200.9844
5/21/2012#Regular Air#21172.5384
8/7/2012#Delivery Truck#19952.96
10/16/2012#Regular Air#20065.9887
12/2/2012#Delivery Truck#15315.7884
12/12/2012#Delivery Truck#15321.409
;
proc means max;
class pdate;
format pdate year4.;
run;

This is the output:

The MEANS Procedure

Analysis Variable : profit
pdate N Obs Maximum
2009 6 34399.46
2010 2 18052.43
2011 3 19200.98
2012 5 21172.54

This should get you started. Proc means can create an output dataset if you like.

If I misinterpreted your question please elaborate and give a sample of the dersired output.

Regards,

- Jan.

All Replies
Solution
‎06-28-2016 09:05 AM
Valued Guide
Posts: 534

## Re: highest value

Hi @Prashant_Ph,

Not entirely certain what you want. So I take a stab guessing you want the max profit per year. You can use proc means for that. Assign the YEAR. format to the date to specifiy the required aggregation level of year.

data profit;
infile cards dlm='#';
length type \$200;
format pdate date9.;
input pdate : mmddyy10. type \$ profit;
cards;
1/6/2009#Delivery Truck#16413.8242
1/7/2009#Regular Air#18527.1684
1/22/2009#Delivery Truck#17506.2518
2/15/2009#Delivery Truck#15227.6924
3/21/2009#Regular Air#34399.4625
8/21/2009#Delivery Truck#15688.9425
1/3/2010#Delivery Truck#18052.4284
10/20/2010#Delivery Truck#15904.1736
5/22/2011#Delivery Truck#19200.9844
11/19/2011#Delivery Truck#18598.6608
12/21/2011#Delivery Truck#19200.9844
5/21/2012#Regular Air#21172.5384
8/7/2012#Delivery Truck#19952.96
10/16/2012#Regular Air#20065.9887
12/2/2012#Delivery Truck#15315.7884
12/12/2012#Delivery Truck#15321.409
;
proc means max;
class pdate;
format pdate year4.;
run;

This is the output:

The MEANS Procedure

Analysis Variable : profit
pdate N Obs Maximum
2009 6 34399.46
2010 2 18052.43
2011 3 19200.98
2012 5 21172.54

This should get you started. Proc means can create an output dataset if you like.

If I misinterpreted your question please elaborate and give a sample of the dersired output.

Regards,

- Jan.

Frequent Contributor
Posts: 128

## Re: highest value

If you want a subset dataset you can select off after the sort.

proc sort data=[my data];  by year profit; run;

data [my data2];

set [my data];

by year profit;

if first.year and last.profit then output;

run;

If it's sorted by profit ascending per year, that should pull out the highest per year.

Super User
Posts: 23,776

## Re: highest value

@MeganE You should take last.year for the highest profit.

proc sort data=[my data];  by year profit; run;

data [my data2];
set [my data];
by year;
if last.year;
run;

Frequent Contributor
Posts: 128

## Re: highest value

Oh, look at that, i flipped them.  Yes, you're right!

Valued Guide
Posts: 534

## Re: highest value

@MeganE @Reeza there is no YEAR in the data that @Prashant_Ph attached.

Frequent Contributor
Posts: 128

## Re: highest value

Really?  I'll admit i didn't look b/c i'm not comfortable opening files like that from people i don't know out on the internet.  But wow.  The original post surely implied year was part of the data...

Super User
Posts: 23,776

## Re: highest value

@MeganE I agree about downloading files and year variable. It's relatively easy to calculate year anyways. Either use Year() function or year format.

Occasional Contributor
Posts: 13

## Re: highest value

Am really thank full @jklaverstijn

🔒 This topic is solved and locked.