BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ybz12003
Rhodochrosite | Level 12

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;
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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;

View solution in original post

6 REPLIES 6
novinosrin
Tourmaline | Level 20

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;
Astounding
PROC Star

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');

ybz12003
Rhodochrosite | Level 12

Hi Astounding,  your code is easy and quick.   Awesome!

SuryaKiran
Meteorite | Level 14

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;
Thanks,
Suryakiran
Andygray
Quartz | Level 8

@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 

ybz12003
Rhodochrosite | Level 12

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.  🙂

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 835 views
  • 3 likes
  • 5 in conversation