Hello:
I have a sample dataset shown below. I would like to do the following:
1. Change the ProduceDate from Character to Date format as MMDDYYYY (such as 06/04/1963).
2. Create a new ReceiveDate which is 90 days from ProduceDate.
3. Create a new ShipDate which is 6 months from ProdeceDate.
Please advice how to do it, thanks.
data test;
infile datalines dlm='|';
input ID $10. ProduceDate : $10. State : $10.;
datalines;
100012556 | 19980411 | GA |
600012956 | 19850321 | IA |
500012586 | 19630604 | CA |
500052586 | 19970530 | TX |
200052576 | 19990702 | OH |
600052577 | 19990806 | TX |
900052578 | 19990429 | NY |
800012578 | 19980527 | NV |
600012878 | 19990911 | FL |
300022578 | 19850821 | PA |
;
Proc sort; by ProduceDate; run;
something like this?
data test;
infile datalines dlm='|';
input ID $10. ProduceDate : $10. State : $10.;
datalines;
100012556 | 19980411 | GA |
600012956 | 19850321 | IA |
500012586 | 19630604 | CA |
500052586 | 19970530 | TX |
200052576 | 19990702 | OH |
600052577 | 19990806 | TX |
900052578 | 19990429 | NY |
800012578 | 19980527 | NV |
600012878 | 19990911 | FL |
300022578 | 19850821 | PA |
;
data want;
set test(rename=ProduceDate=_ProduceDate);
ProduceDate=input(_ProduceDate,yymmdd10.);
ReceiveDate =intnx('days',ProduceDate,90);
ShipDate=intnx('month',ProduceDate,6);
format ProduceDate ReceiveDate ShipDate MMDDYY10.;
drop _:;
run;
something like this?
data test;
infile datalines dlm='|';
input ID $10. ProduceDate : $10. State : $10.;
datalines;
100012556 | 19980411 | GA |
600012956 | 19850321 | IA |
500012586 | 19630604 | CA |
500052586 | 19970530 | TX |
200052576 | 19990702 | OH |
600052577 | 19990806 | TX |
900052578 | 19990429 | NY |
800012578 | 19980527 | NV |
600012878 | 19990911 | FL |
300022578 | 19850821 | PA |
;
data want;
set test(rename=ProduceDate=_ProduceDate);
ProduceDate=input(_ProduceDate,yymmdd10.);
ReceiveDate =intnx('days',ProduceDate,90);
ShipDate=intnx('month',ProduceDate,6);
format ProduceDate ReceiveDate ShipDate MMDDYY10.;
drop _:;
run;
ProduceDate looks good.
ReceiveDate looks right, but could easily be simplified:
ReceiveDate = ProduceDate + 90;
ShipDate will revert to the first day of the month. To get 6 months later, while using the same day of the month:
ShipDate = intnx('month', ProduceDate, 6, 'same');
Hi Astounding, your code is easy and quick. Awesome!
Read the ProduceDate as Date instead of Char. If you need same day 6 months from the ProduceDate then use "SameDay" in INTNX
data test;
format ProduceDate ShipDate ReceiveDate yymmdd10.;
infile datalines dlm='|';
input ID $10. ProduceDate : yymmdd8. State : $10.;
ReceiveDate =intnx('days',ProduceDate,90);
ShipDate=intnx('month',ProduceDate,6,"sameday");
datalines;
100012556 | 19980411 | GA |
600012956 | 19850321 | IA |
500012586 | 19630604 | CA |
500052586 | 19970530 | TX |
200052576 | 19990702 | OH |
600052577 | 19990806 | TX |
900052578 | 19990429 | NY |
800012578 | 19980527 | NV |
600012878 | 19990911 | FL |
300022578 | 19850821 | PA |
;
Run;
@Astounding has already proposed "SameDay" in INTNX to @novinosrin solution.
@ybz12003's 1st requirement is 1. Change the ProduceDate from Character to Date format as MMDDYYYY probably means his/her real data has a character date
Thank you so much for your wonderful help. I combined Novinosrin and Astounding's codes to get it work. Unfortunately, I only could give one solution to one person. Because Novinosin answered the Q first, I give the credit to him. But I am appreciated all of your kind help. 🙂
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.