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.
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.
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.
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.
@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;
Oh, look at that, i flipped them. Yes, you're right!
@MeganE @Reeza there is no YEAR in the data that @Prashant_Ph attached.
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...
@MeganE I agree about downloading files and year variable. It's relatively easy to calculate year anyways. Either use Year() function or year format.
Am really thank full @jklaverstijnJklaverstin you have solved my question, actually i tried in many ways but you have given me perfect solution.
now i can continue my practice
And thanks for others too who replayed
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.