Date: Tue, 21 Aug 2007 09:25:43 -0400
Reply-To: Jim Groeneveld <jim4stat@YAHOO.CO.UK>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jim Groeneveld <jim4stat@YAHOO.CO.UK>
Subject: Re: to calculate percentage difference
Hi Anitha,
Well that isn't an example, that could be the complete database.
Please don't include so much data in an email again.
The amount of data does not influence the solution.
Anyway, you have monthly data in different records, but you want monthly
differences within the same record.
That means that you firstly have to fold your structure.
There are various ways to do so, like uing PROC TRANSPOSE or a data step,
but a dedicated way to do so is to use the macro MR2RM.
See also the thread "Proc Transpose". Download MR2RM.zip with MR2RM.sas
inside from http://home.hccnet.nl/jim.groeneveld/software/SASmacro and also
follow instructions in MR2RM.txt (downloading a few more auxiliary macros).
With the macro specify the Data= and OUT= datasets and furthermore:
Index=Month, ByList=CustNum, MRlist=PerSales
You will get the variables PerSales1 to PerSales5 that you can subtract from
each other as desired.
If, on the other hand, you want a single difference variable for each record
between consecutive records, you would have to use the LAG or DIF function
(or a construction using RETAIN) to determine differences between the
records. And by using the FIRST.variable construct you would have to reset
the difference to missing if it is the first record for a customer.
Good luck and let me know whether these suggestions were informative.
Regards - Jim.
--
Jim Groeneveld, Netherlands
Statistician, SAS consultant
home.hccnet.nl/jim.groeneveld
On Tue, 21 Aug 2007 05:44:13 -0700, anitha <uma.anitha@GMAIL.COM> wrote:
>hi
> we have data for first five months as given below in which we
>calculated percentage for sales in each month(per_sales).but v have to
>calculate percentage difference for each two concecutive months like 2
>to 1,3-2,4-3,5-4.the problem s that some months are missing in that
>percentage.
>so, v have to take 0 for that missing months and do percentage
>difference.
>so if u knw ans for this pls mail me.
>Percent change in sales in each month starting from month 2
>(pct_sls_2_1, pct_sls_3_2, pct_sls_4_3, pct_sls_5_4)
>
>data transaction;
>input custnum $ month sale_mon tot_sales per_sales;
>cards;
>1004159 1 75000 120240 62.375249501
>1004159 2 24210 120240 20.134730539
>1004159 3 21000 120240 17.46506986
>1004159 5 30 120240 0.0249500998
>1014885 1 9100 48490 18.766756032
>1014885 2 22890 48490 47.205609404
>1014885 4 16500 48490 34.027634564
>1020600 1 44160 98310 44.919133354
>1020600 3 950 98310 0.9663309938
>1020600 5 53200 98310 54.114535653
>1031528 1 3850 3850 100
>1040996 2 50 77850 0.0642260758
>1040996 3 52800 77850 67.822736031
>1040996 4 5500 77850 7.0648683365
>1040996 5 19500 77850 25.048169557
>1047016 1 72800 73410 99.169050538
>1047016 4 540 73410 0.7355946056
>1047016 5 70 73410 0.0953548563
>1061037 1 690 55350 1.2466124661
>1061037 2 660 55350 1.1924119241
>1061037 3 31500 55350 56.910569106
>1061037 5 22500 55350 40.650406504
>107262 4 1750 4750 36.842105263
>107262 5 3000 4750 63.157894737
[.........cut most of the example data.........]
>;
>run;