data suzuki;
input purchase_date $;
datalines;
23OCT2021
;
proc print;
run;
data servicing;
set suzuki;
day=intnx(input('day',purchase_date,30),date9.);
informat purchase_date date9.;
format purchase_date date9.;
proc print;
run;
how to get output dynamically
Days | Servicing_Due_Date |
30-45 | |
120-135 | |
240-255 | |
365-380 | |
485-500 | |
605-620 | |
725-740 | |
845-860 |
Hi,
1) your code is generating errors, try this one:
data suzuki;
input purchase_date date9.;
datalines;
23OCT2021
;
run;
proc print;
run;
data servicing;
set suzuki;
day=intnx('day',purchase_date,30);
informat purchase_date day date9.;
format purchase_date day date9.;
run;
proc print;
run;
2) explain what do you mean by "dynamic".
Bart
data suzuki;
input purchase_date date9.;
format purchase_date date9.;
datalines;
23OCT2020
;
run;
proc print;
run;
data servicing;
set suzuki;
day=intnx('day',purchase_date,30);
informat purchase_date day date9.;
format purchase_date day date9.;
run;
proc print;
run;
i want servicing _due_date acoording days as below
Days | Servicing_Due_Date |
30-45 | |
120-135 | |
240-255 | |
365-380 | |
485-500 | |
605-620 | |
725-740 | |
845-860 |
@BrahmanandaRao wrote:
data suzuki; input purchase_date date9.; format purchase_date date9.; datalines; 23OCT2020 ; run; proc print; run; data servicing; set suzuki; day=intnx('day',purchase_date,30); informat purchase_date day date9.; format purchase_date day date9.; run; proc print; run;
i want servicing _due_date acoording days as below
Days Servicing_Due_Date 30-45 120-135 240-255 365-380 485-500 605-620 725-740 845-860
I don't see any connection between the data you have posted and the table showing the expected result. The variable "Days" is nowhere in the data. So please explain what you are trying to achieve.
data servicing;
purchase_date='23OCT2020'd;
1st_servicing=intnx('day',purchase_date,30);
2st_servicing=intnx('day',purchase_date,120);
3st_servicing=intnx('day',purchase_date,240);
4st_servicing=intnx('day',purchase_date,365);
5st_servicing=intnx('day',purchase_date,485);
6st_servicing=intnx('day',purchase_date,605);
7st_servicing=intnx('day',purchase_date,725);
8st_servicing=intnx('day',purchase_date,845);
informat purchase_date day date9.;
format purchase_date day date9.;
run;
proc print;
run;
@BrahmanandaRao wrote:
data servicing; purchase_date='23OCT2020'd; 1st_servicing=intnx('day',purchase_date,30); 2st_servicing=intnx('day',purchase_date,120); 3st_servicing=intnx('day',purchase_date,240); 4st_servicing=intnx('day',purchase_date,365); 5st_servicing=intnx('day',purchase_date,485); 6st_servicing=intnx('day',purchase_date,605); 7st_servicing=intnx('day',purchase_date,725); 8st_servicing=intnx('day',purchase_date,845); informat purchase_date day date9.; format purchase_date day date9.; run; proc print; run;
Sorry, but as long as you don't write something explaining your intention, it is impossible to help you.
Please do not play practical jokes on us:
69 data servicing; 70 purchase_date='23OCT2020'd; 71 1st_servicing=intnx('day',purchase_date,30); _ 180 ERROR 180-322: Statement is not valid or it is used out of proper order. 72 73 2st_servicing=intnx('day',purchase_date,120); _ 180 ERROR 180-322: Statement is not valid or it is used out of proper order. 74 75 3st_servicing=intnx('day',purchase_date,240); _ 180 ERROR 180-322: Statement is not valid or it is used out of proper order. 76 77 4st_servicing=intnx('day',purchase_date,365); _ 180 ERROR 180-322: Statement is not valid or it is used out of proper order. 78 79 5st_servicing=intnx('day',purchase_date,485); _ 180 ERROR 180-322: Statement is not valid or it is used out of proper order. 80 81 6st_servicing=intnx('day',purchase_date,605); _ 180 ERROR 180-322: Statement is not valid or it is used out of proper order. 82 83 7st_servicing=intnx('day',purchase_date,725); _ 180 ERROR 180-322: Statement is not valid or it is used out of proper order. 84 85 8st_servicing=intnx('day',purchase_date,845); _ 180 ERROR 180-322: Statement is not valid or it is used out of proper order. 86 87 informat purchase_date day date9.; 88 format purchase_date day date9.; 89 run; NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set WORK.SERVICING may be incomplete. When this step was stopped there were 0 observations and 2 variables.
Do you mean something like this:
data suzuki;
input purchase_date date9.;
datalines;
23OCT2021
;
run;
proc print;
run;
data servicing;
set suzuki;
do D = 30,120,240,365,485,605,725,845; drop d;
days = catx("-", D, D+15);
day_start = intnx('day', purchase_date, d); /* equivalent to: day_start = purchase_date + d; */
day_end = day_start + 15;
Servicing_Due_Date = catx("-", put(day_start,date9.), put(day_end,date9.));
output;
end;
format purchase_date day_start day_end date9.;
run;
proc print;
run;
Bart
Hi Yabwon
Thanks for your solution what i expected suppose i want 100 services then how to write dynamic code
Here what I think might be another approach.
data have; input purchase_date date9.; format purchase_date date9.; datalines; 23OCT2021 ; data want; set have; array d(8) _temporary_ (45,135,255,380,500,620,740,860); do i=1 to dim(d); days=d[i]; service_date= intnx('days',purchase_date,days,'e'); output; end; format service_date date9.; drop i; run; proc format; value service_days 45= ' 30- 45' 135='120-135' 255='240-255' 380='365-380' 500='485-500' 620='605-620' 740='725-740' 860='845-860' ; run; proc print data=want noobs; format days service_days.; run;
However to do anything "dynamic" requires the explicit rules on what is to be dynamic and how to make the values.
Do you want to do a frequency on intervals? Intervals between dates are calculated with INTCK.
Please be more specific in describing your task, and provide details. Terse one-liners will not help. Spend at least as much effort in your questions as we do in our answers.
Your purchase_date variable is not a SAS date, so you can't use it as argument in the INTNX function.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.