Write and run SAS programs in your web browser

Add Date Field mmddyy8. to dataset and update from Char Date field

Accepted Solution Solved
Reply
Contributor
Posts: 58
Accepted Solution

Add Date Field mmddyy8. to dataset and update from Char Date field

I have a dataset with a character date field (Source_Date Char(35)) with data in this format, "mmddyy" (no slashes) .  I want to:

 

1.  Add a new date field,  "Source_Date_dte mmddyy8."

2.  Update the new Source_Date_dte field with the date value from the Source_Date.

 

For Example:               New field value

060116-------------------> 06/01/16

 

Here is my code attempt:

data ALL_MONTHS_LOAN_DETAIL_new;

set ALL_MONTHS_LOAN_DETAIL;

Source_Date_dte=input(Source_Date, 6.);

format Source_Date_dte mmddyy8.;

run:

 

This code produces a new field Source_Date_dte Character 15 with format $MDDYY10 and no data populated in the new field.

 

Help Please

 

 

 


Accepted Solutions
Solution
‎07-13-2016 12:10 PM
Contributor
Posts: 58

Re: Add Date Field mmddyy8. to dataset and update from Char Date field

 

Perfect!

 

Thank you!

View solution in original post


All Replies
Grand Advisor
Posts: 16,408

Re: Add Date Field mmddyy8. to dataset and update from Char Date field

Use the appropriate date informat. In your input function try mmddyy6. as the informat rather than 6. 

Solution
‎07-13-2016 12:10 PM
Contributor
Posts: 58

Re: Add Date Field mmddyy8. to dataset and update from Char Date field

 

Perfect!

 

Thank you!

Respected Advisor
Posts: 4,648

Re: Add Date Field mmddyy8. to dataset and update from Char Date field

Your statement would always create a numeric variable (even if you need to adjust it according to Reeza's suggestion, the same applies).  If you are getting a character variable as the result, it is because SOURCE_DATE_DTE already exists (as a character variable) within the incoming data set ALL_MONTH_LOANS_DETAIL.  It should be dropped from the input.

Post a Question
Discussion Stats
  • 3 replies
  • 241 views
  • 0 likes
  • 3 in conversation