?
Solved

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

Posted on 2013-11-20
2
Medium Priority
?
4,754 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
[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
2 Comments
 
LVL 8

Accepted Solution

by:
ShannonEE earned 1000 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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

743 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