Solved

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

Posted on 2013-11-20
2
4,286 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

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

I guess that all of us know that caching the data usually increase the performance, but I worried if all of us are aware about the risk that caching the data provides and how to minimize this.  That’s the reason why I decided to write this short art…
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
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…

910 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now