I'm a little bit stuck with a request from my boss who wants to know how long it takes a customer to spend 75% of a credit voucher. The customer can use the voucher many times for many variously priced goods but she wants the time period that it takes to meet or exceed 75% of the value. Vouchers can be for any amount but are normally in the non-rounded hundreds to a few thousands (i.e $543.00 may be a value).
I was planning to firstly get the value of each voucher, then to begin adding up the purchases until the sum is equal to or exceeds 75% of the voucher value, then taking the date when that happens and subtracting the issue date of the voucher (or the date of the voucher's first use). Not sure how to go about the coding yet but conceptually I'm looking to try something like (plain text version as opposed to an attempt to code):
eg, for a voucher that is $1000.00,
array(date_of_purchase) _temp_;
do I = 1 to (total number of purchases on a voucher);
running_value=_value +purchase_value
do until (running_value =1000 *0.75);
Number_purchases=I;
duration=date_of_purchase(I) - voucher_issue_date;
end;
end;
The data are structured in SAS with each row having a customer id, date of purchase, value of purchase and an indicator if the purchase is from a voucher (as well as the goods, quantity etc.)
Has anyone done anything similar that they could please share with me? My boss knows that this is likely on the verge of my skill set and that I'm seeking help to get this done ("it's a learning experience!"). I'm not sure if this is a simple process that I am over complicating.
Thanks
Gordon
Create a second column that indicates the purchase as a percentage of the voucher, PROC FREQ can do this.
Then if you plot the CDF of that distribution, wherever it hits 75% is the value you want. PROC UNIVARIATE will get you the CDF. I'm not yet sure if you'd do that for each 'voucher' individually and then average the time or if it makes sense to look at the full data distribution somehow.
If you need further help post data that illustrates your issue, feel free to make fake data or reference a SASHELP data set that is close enough to your data.
I did not look into if your approach would work but in general, I prefer using SAS PROCS than coding my own - less changes of mistake that way.
Here are instructions on how to provide sample data as a data step:
https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...
@gordononline wrote:
I'm a little bit stuck with a request from my boss who wants to know how long it takes a customer to spend 75% of a credit voucher. The customer can use the voucher many times for many variously priced goods but she wants the time period that it takes to meet or exceed 75% of the value. Vouchers can be for any amount but are normally in the non-rounded hundreds to a few thousands (i.e $543.00 may be a value).
I was planning to firstly get the value of each voucher, then to begin adding up the purchases until the sum is equal to or exceeds 75% of the voucher value, then taking the date when that happens and subtracting the issue date of the voucher (or the date of the voucher's first use). Not sure how to go about the coding yet but conceptually I'm looking to try something like (plain text version as opposed to an attempt to code):
eg, for a voucher that is $1000.00,
array(date_of_purchase) _temp_;
do I = 1 to (total number of purchases on a voucher);
running_value=_value +purchase_value
do until (running_value =1000 *0.75);
Number_purchases=I;
duration=date_of_purchase(I) - voucher_issue_date;
end;
end;
The data are structured in SAS with each row having a customer id, date of purchase, value of purchase and an indicator if the purchase is from a voucher (as well as the goods, quantity etc.)
Has anyone done anything similar that they could please share with me? My boss knows that this is likely on the verge of my skill set and that I'm seeking help to get this done ("it's a learning experience!"). I'm not sure if this is a simple process that I am over complicating.
Thanks
Gordon
So you have a dataset like this:
data purchases;
infile datalines truncover;
input id $ date :yymmdd10. amount indicator :$1.;
format date yymmddd10.;
datalines;
0123 2020-03-30 100 Y
;
but from where do you get the voucher amount?
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.