Solved

How do I convert a 6 position date format to a 10 position date format?

Posted on 2011-02-21
15
757 Views
Last Modified: 2013-11-16
Hi All,

How do I convert the following date to a MM/DD/YYYY format?

112310 to 11/23/2010

Thanks,

SASnewbie
0
Comment
Question by:SASnewbie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
15 Comments
 
LVL 11

Expert Comment

by:theartfuldazzler
ID: 34945763
Hi

Assuming the date is stored as text then:

DATA _NULL_;
  Old_date = '112310';
  SAS_Date = INPUT(Old_date, mmddyy.);
  New_date = PUT(SAS_Date, mmddyy10.);
  PUT _ALL_;
RUN;

Effectively, this ocde converts a text field to a SAS date, and then makes that SAS Date into a new text field in the format mm/dd/yyyy.

0
 

Author Comment

by:SASnewbie
ID: 34945779
Hi theartfuldazzler,

Thanks for responding so quickly.

Is there a way to keep the 'Old_date" name?
0
 
LVL 11

Expert Comment

by:theartfuldazzler
ID: 34945828
Hi

DATA _NULL_;
  Old_date = '112310';
  SAS_Date = INPUT(Old_date, mmddyy.);
  Old_date = PUT(SAS_Date, mmddyy10.);
  PUT _ALL_;
DROP SAS_Date;
RUN;
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 11

Expert Comment

by:theartfuldazzler
ID: 34945838
Hi

You might have an issue with the length of the Old_Date.  If you place a format statement before the SET statement, it should work.


DATA _NULL_;
format Old_Date $10.;
  Old_date = '112310';
  SAS_Date = INPUT(Old_date, mmddyy.);
  New_date = PUT(SAS_Date, mmddyy10.);
  PUT _ALL_;
RUN;
0
 

Author Comment

by:SASnewbie
ID: 34945840
Thanks,
Let me try it and be right back.
0
 

Author Comment

by:SASnewbie
ID: 34945893
Hi,

I'm not getting it... Here is the section of the log with the error message.

2652  Date = input(stat_date,mmddyy.);
2653  Stat_date = put(date, mmddyy10.);
                            ---------
                            48
ERROR 48-59: The format $MMDDYY was not found or could not be loaded.

stat_date is in the mmddyy format, is text with length $6.
0
 
LVL 11

Accepted Solution

by:
theartfuldazzler earned 500 total points
ID: 34945923
Hi

It looks like you have previously defined the "date" variable as text as well...  The date variable must be numeric...

In the two lines you sent me - try changing to:

x_Date = input(stat_date,mmddyy.);
Stat_date = put(x_date, mmddyy10.);
0
 

Author Comment

by:SASnewbie
ID: 34945955
Okay Thanks,
I will be back in an hour...
0
 
LVL 11

Expert Comment

by:theartfuldazzler
ID: 34946040
Hi

Its 10pm on my side of the world, I will look again tomorrow first thing
0
 

Author Comment

by:SASnewbie
ID: 34969628
I was able to make the conversion:

stat2_date = input(stat_date,mmddyy6.);
format stat2_date mmddyy10.;
stat_date = put(stat2_date,mmddyy10.);

Thanks,
0
 

Author Comment

by:SASnewbie
ID: 34969668
Please cancel this request to close without assigning points
0
 
LVL 11

Expert Comment

by:theartfuldazzler
ID: 34969924
Hi

Just interested - but the answer I gave works - and is identical to your answer...  why no points?
0
 

Author Comment

by:SASnewbie
ID: 34970400
Hi theartfuldazzler,

I put in a request for the cancel so I can give you the points.

Sorry about that.
0
 
LVL 11

Expert Comment

by:theartfuldazzler
ID: 34977198
As per comment ID: 34970400, the author agrees that comment ID: 34945923 is the correct solution, and should be granted the points.
0
 

Author Comment

by:SASnewbie
ID: 34980113
Thanks again!
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MySql Workbench outputting "OK" as result of queries. 5 46
subtr returning incorrect value 8 89
T-SQL Query - Group By Year 3 51
mysql vs miscrosoft sql server 6 52
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

742 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question