Solved

Converting a character column to a date in a proc sql statement in SAS

Posted on 2013-11-20
2
4,473 Views
Last Modified: 2013-11-21
Experts,

If I a column that is defined as $10. and contains a date value '2003-02-25' is there a way to read this column into Proc Sql statement in sas and convert to mmddyyyy format.
0
Comment
Question by:morinia
2 Comments
 
LVL 8

Accepted Solution

by:
ShannonEE earned 250 total points
ID: 39664790
Three ways

One:
Convert character data to a date (which is numerical being the number of days from 1980) and apply the appropriate mmddyy to it, so that it will display as you want it.  But the new variable will not be character!

Two:
Use nested input and put functions to convert.

Three:
Use string manipulation functions to copy chars 6 7 9 10 1 2 3 4 in that order.

------
For example, in the last case if the $10 variable is "processdate" then something like the below would work.

create table new as
select   cats(substr(process date, 9, 2), substr(processdate, 9, 2), substr(processdate, 1, 4))  length=10 format=$10. as newprocessdate,
             ...
            ...

Ian
0
 
LVL 14

Assisted Solution

by:Aloysius Low
Aloysius Low earned 250 total points
ID: 39664873
if you want the end result to be a date, but displayed in mmddyyyy, then use the following line within your select statement:
input(datestr, yymmdd10.) as newfieldname format mmddyyn8.

if you want the end result to appear as text,
put(input(datestr, yymmdd10.), mmddyyn8.)
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
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…

685 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