Solved

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

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
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…

762 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

13 Experts available now in Live!

Get 1:1 Help Now