I'm wondering how I would write a do loop to take care of each observation:
Call this dataset "above":
N Date Amount Term
1 1/10/15 120 12
2 2/1/15 60 12
I originally had:
data new;
set above;
do until(months=term);
months+1;
deferred_rev = amount/term;
deferred_date=intnx('month',date,months-1,'same');
output;
run;
But, I want it to do this for each transaction to defer the revenue... in this event the months kept counting and it didn't treat each row as the subset. I have a feeling this needs to be a nested iterative do loop...
The term represents how many months to the next billing event, however that means the total amount needs to be split over 12 months in this case. The output ideally would look like:
N Date Amount Term Deferred_Date Months Deferred_Rev
1 1/10/15 120 12 1/10 1 10
2 1/10/15 120 12 2/10 2 10
3
4
5
...
13 2/1/15 60 12 2/1/15 1 5
14 2/1/15 60 12 3/1/15 2 5
...
Just use a normal DO loop .
data above ;
informat date mmddyy10. ;
format date yymmdd10. ;
input id Date Amount Term;
cards;
1 1/10/15 120 12
2 2/1/15 60 12
;;;;
data new;
set above;
do month = 1 to term ;
deferred_rev = amount/term;
deferred_date=intnx('month',date,month-1,'same');
output;
end;
run;
proc print; run;
Note: I removed the S from the loop counter MONTH to avoid confusion on meaning since it is the month number and not the number of months.
Just use a normal DO loop .
data above ;
informat date mmddyy10. ;
format date yymmdd10. ;
input id Date Amount Term;
cards;
1 1/10/15 120 12
2 2/1/15 60 12
;;;;
data new;
set above;
do month = 1 to term ;
deferred_rev = amount/term;
deferred_date=intnx('month',date,month-1,'same');
output;
end;
run;
proc print; run;
Note: I removed the S from the loop counter MONTH to avoid confusion on meaning since it is the month number and not the number of months.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.