Reporting period

10 pts.
Tags:
SAS
SAS 9.2
Need help to create 12-month running total by customer_id which include the following: 1. MonthlyTotal 2. Monthly Percentage, 3. Previous Month total, 3. YTD 4 . YTD Percentage Below is an example of what I am trying to accomplish. Within the example there are customer_id , 24 and 25. Each row of data represents one month along with sales amount. The variable I would like to calculate is the "sales_amout", which is the 12 month running total within the customer_id. As you can see, the first 12 "sales_amount" is blank because there hasn't been 12 months of data yet. this Data table for example is a short list of 12 months of data: customer_id Month Sales_Amount 23 01JAN2013 23 02JAN2013 23 03JAN2012 24 01DEC2012 10.00 . 24 02DEC2012 30.00 24 03DEC2012 50.00 Here is my code and code is not working: Data TOTAL_SALES; Set SALES; /** allows first. and last. processing **/ By customer_id month prev_month; RETAIN total 0 monthTotal 0 month1 – month12 prevmonth_tot 0; if sales_amount = . then delete; /* month 1 though month 12*/ ARRAY sales_amount {12} $ month1-month12; IF first.sales_amount THEN do; do i = 1 to 12; sales(i)=''; end; end; n+1; sales(n)=sales_amount; IF last.customer_id THEN do n=0; output; end; /*Month Total*/ month_total + sale_amount; total + sale_amount; total = sum(of month1 – month12); total + sales_amount if FIRST.customer_id then monthTotal = 0 ; if LAST.customer_id then output ; /*Month Percentage*/ month/month pct=sales_amount/total /*previous month*/ Array mths {12} month1 – month12; do i = 2 to 12; index1 = month(date); /** extract month from date value **/ mths{index1} = mths{index1} + sales_amount; if first.customer_id{i} then do prevmonth_tot{i} =0; if Last.customer_id{i} then output; /*YTD*/ Array months {12} month1 – month12; index2 = month(date); /** extract month from date value **/ months{index} = months{index} + sales_amount; if last.customer_id then do; /** last observation for customer **/ YTD_total = sum(of month1 – month12); /** year-to-date total **/ output; /** output one observation per customer **/ do i = 1 to 12; months{i} = 0; /** reset to zero for next customer **/ end; end; /*YTD* Percentage*/ do i=12; ytd = (i)/total
Software/Hardware used:
sas

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following