Solved

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

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
LDAP find expired users 8 92
Insert with SET how to handle join 6 69
Simple SQL query from two tables 13 51
Mysql Left Join Case 10 41
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
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…

815 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

11 Experts available now in Live!

Get 1:1 Help Now