comparision for present &previous year data in few months

Reply
Occasional Contributor
Posts: 15

comparision for present &previous year data in few months

I HAVE DATA LIKE THIS

DATE AMOUNT$;

31/01/2014  5000

28/02/2014  6000

30/03/2014  7000

31/12/2013  3400

31/11/2013  5000

28/10/2013  6000

30/09/2013  7000

31/08/2013  3400

30/07/2013  4000

31/06/2013  5000

28/05/2013  6000

30/04/2013  7000

31/03/2013  3400

28/02/2013  5000

31/01/2013  6000

MY REQUIRMENT IS

PICK THE DATA IN MAX YEAR OF DATA AND BEFORE YEAR DATA

ADDING FOR COMPARISION

FOR EXAMPLE;

    MAX YEAR OF DATA              BEFORE YEAR DATA

       2014                             2013

(  5000+6000+7000=18000)      (6000+5000+3400=14400)

with out mention year&month like(2014,2013,jan,feb,mar)  using max year ,it can possible

help me

Grand Advisor
Posts: 9,571

Re: comparision for present &previous year data in few months


data have;
input DATE : ddmmyy10. AMOUNT;
format DATE  ddmmyy10.;
cards;
31/01/2014  5000
28/02/2014  6000
30/03/2014  7000
31/12/2013  3400
30/11/2013  5000
28/10/2013  6000
30/09/2013  7000
31/08/2013  3400
30/07/2013  4000
30/06/2013  5000
28/05/2013  6000
30/04/2013  7000
31/03/2013  3400
28/02/2013  5000
31/01/2013  6000
 ;
 run;
proc sql;
select sum(AMOUNT) as MAX_YEAR,     sum(BEFORE_YEAR) as BEFORE_YEAR
from (
 select  *,(select sum(AMOUNT) from have where year(DATE)=year(a.DATE)-1 and month(DATE)=month(a.DATE))      as BEFORE_YEAR
  from (select * from have having year(DATE)=max(year(DATE))) as a
);
quit;

Xia Keshan

Occasional Contributor
Posts: 15

Re: comparision for present &previous year data in few months

code is working,than you sir

Ask a Question
Discussion stats
  • 2 replies
  • 152 views
  • 0 likes
  • 2 in conversation