Desktop productivity for business analysts and programmers

how to compute minimum and maxium values of one variable grouped by month and year

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 87
Accepted Solution

how to compute minimum and maxium values of one variable grouped by month and year

For the following data,

 

How can I compute Min and Max of MV in an individual month and year?

Also I don't know how to format Year and Month so that they do appear as date type YYYY and MM.

 

Please help.

 

data have;
infile cards truncover expandtabs;
input MC $ Year Month MV;
cards;
US000401 2015 3 2470237.00
US000401 2015 3 2456056.00
US000401 2015 3 2455033.00
US000401 2015 4 2514014.00
US000401 2015 4 2513327.00
US000401 2015 4 2514014.00
US000401 2015 4 2493916.00
US000401 2015 4 2492461.00
US000401 2015 4 2491547.00
US000401 2015 5 2543793.00
US000401 2015 5 2543359.00
US000401 2015 5 2518758.00
US000401 2015 5 2516837.00
US000401 2015 5 2515140.00
US000401 2015 6 2564013.00
US000401 2015 6 2563221.00
US000401 2015 6 2546570.00
US000401 2015 6 2545730.00
US000401 2015 6 2544672.00
US000401 2015 7 2585750.00
US000401 2015 7 2583685.00
US000401 2015 7 2566615.00
US000401 2015 7 2565634.00
US000401 2015 7 2564660.00
US000401 2015 8 2613465.00
US000401 2015 8 2611991.00
US000401 2015 8 2588284.00
US000401 2015 8 2587931.00
US000401 2015 8 2586864.00
US000401 2015 9 2637445.00
US000401 2015 9 2636071.00
US000401 2015 9 2615970.00
US000401 2015 9 2615112.00
US000401 2015 9 2614320.00
US000401 2015 10 2669780.00
US000401 2015 10 2668465.00
US000401 2015 10 2667387.00
US000401 2015 10 2639241.00
US000401 2015 10 2638899.00
US000401 2015 10 2638631.00
US000401 2015 11 2703315.00
US000401 2015 11 2702390.00
US000401 2015 11 2674313.00
US000401 2015 11 2673004.00
US000401 2015 11 2671232.00
US000401 2015 12 2722479.00
US000401 2015 12 2721936.00
US000401 2015 12 2705452.00
US000401 2015 12 2703832.00
;
run;

 

Thanks.


Accepted Solutions
Solution
‎12-27-2016 08:58 AM
Respected Advisor
Posts: 3,775

Re: how to compute minimum and maxium values of one variable grouped by month and year

data have;
   input MC $ Year Month MV;
   yymm = mdy(month,1,year);
   format yymm yymon7.;
   drop year month;
   cards;
US000401 2015 3 2470237.00
US000401 2015 3 2456056.00
US000401 2015 3 2455033.00
US000401 2015 4 2514014.00
US000401 2015 4 2513327.00
US000401 2015 4 2514014.00
US000401 2015 4 2493916.00
US000401 2015 4 2492461.00
US000401 2015 4 2491547.00
US000401 2015 5 2543793.00
US000401 2015 5 2543359.00
US000401 2015 5 2518758.00
US000401 2015 5 2516837.00
US000401 2015 5 2515140.00
US000401 2015 6 2564013.00
US000401 2015 6 2563221.00
US000401 2015 6 2546570.00
US000401 2015 6 2545730.00
US000401 2015 6 2544672.00
US000401 2015 7 2585750.00
US000401 2015 7 2583685.00
US000401 2015 7 2566615.00
US000401 2015 7 2565634.00
US000401 2015 7 2564660.00
US000401 2015 8 2613465.00
US000401 2015 8 2611991.00
US000401 2015 8 2588284.00
US000401 2015 8 2587931.00
US000401 2015 8 2586864.00
US000401 2015 9 2637445.00
US000401 2015 9 2636071.00
US000401 2015 9 2615970.00
US000401 2015 9 2615112.00
US000401 2015 9 2614320.00
US000401 2015 10 2669780.00
US000401 2015 10 2668465.00
US000401 2015 10 2667387.00
US000401 2015 10 2639241.00
US000401 2015 10 2638899.00
US000401 2015 10 2638631.00
US000401 2015 11 2703315.00
US000401 2015 11 2702390.00
US000401 2015 11 2674313.00
US000401 2015 11 2673004.00
US000401 2015 11 2671232.00
US000401 2015 12 2722479.00
US000401 2015 12 2721936.00
US000401 2015 12 2705452.00
US000401 2015 12 2703832.00
;;;;
   run;
proc print;
   run;
proc summary data=have nway;
   class mc yymm;
   var mv;
   output out=stats(drop=_type_) min=min max=max;
   run;
proc print;
   run;

View solution in original post


All Replies
Solution
‎12-27-2016 08:58 AM
Respected Advisor
Posts: 3,775

Re: how to compute minimum and maxium values of one variable grouped by month and year

data have;
   input MC $ Year Month MV;
   yymm = mdy(month,1,year);
   format yymm yymon7.;
   drop year month;
   cards;
US000401 2015 3 2470237.00
US000401 2015 3 2456056.00
US000401 2015 3 2455033.00
US000401 2015 4 2514014.00
US000401 2015 4 2513327.00
US000401 2015 4 2514014.00
US000401 2015 4 2493916.00
US000401 2015 4 2492461.00
US000401 2015 4 2491547.00
US000401 2015 5 2543793.00
US000401 2015 5 2543359.00
US000401 2015 5 2518758.00
US000401 2015 5 2516837.00
US000401 2015 5 2515140.00
US000401 2015 6 2564013.00
US000401 2015 6 2563221.00
US000401 2015 6 2546570.00
US000401 2015 6 2545730.00
US000401 2015 6 2544672.00
US000401 2015 7 2585750.00
US000401 2015 7 2583685.00
US000401 2015 7 2566615.00
US000401 2015 7 2565634.00
US000401 2015 7 2564660.00
US000401 2015 8 2613465.00
US000401 2015 8 2611991.00
US000401 2015 8 2588284.00
US000401 2015 8 2587931.00
US000401 2015 8 2586864.00
US000401 2015 9 2637445.00
US000401 2015 9 2636071.00
US000401 2015 9 2615970.00
US000401 2015 9 2615112.00
US000401 2015 9 2614320.00
US000401 2015 10 2669780.00
US000401 2015 10 2668465.00
US000401 2015 10 2667387.00
US000401 2015 10 2639241.00
US000401 2015 10 2638899.00
US000401 2015 10 2638631.00
US000401 2015 11 2703315.00
US000401 2015 11 2702390.00
US000401 2015 11 2674313.00
US000401 2015 11 2673004.00
US000401 2015 11 2671232.00
US000401 2015 12 2722479.00
US000401 2015 12 2721936.00
US000401 2015 12 2705452.00
US000401 2015 12 2703832.00
;;;;
   run;
proc print;
   run;
proc summary data=have nway;
   class mc yymm;
   var mv;
   output out=stats(drop=_type_) min=min max=max;
   run;
proc print;
   run;
Frequent Contributor
Posts: 87

Re: how to compute minimum and maxium values of one variable grouped by month and year

Just couple of modifications:

YearMonth = mdy(Month,1,Year);
format YearMonth monyy7.;

and...

proc summary data=have nway;
class MC YearMonth;
var MV;
output out=stats(drop=_type_ _FREQ_) min=MinMV max=MaxMV;
run;
Esteemed Advisor
Posts: 6,646

Re: how to compute minimum and maxium values of one variable grouped by month and year

Kudos for a well-formulated question with nice example data. No miracle it got an immediate solution.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 303 views
  • 5 likes
  • 3 in conversation