DATA Step, Macro, Functions and more

Text to Number (Dates)

Accepted Solution Solved
Reply
Contributor
Posts: 26
Accepted Solution

Text to Number (Dates)

Hi - 

 

I imported a file into SAS and some columns were converted into number format while others into text? why is that? how do i ensure that columns are imported the way I wanted? is there a way?

 

Im using PROC SQL.. 

one of my columns that is in a TEXT format is a date  15JUL2016:00:00:00

I want to change it to a date9 format but its not letting me because its in text so I tried to do input(act_date,12.0) but when i opened the new table that column was ALL blank so the input did not work?

 

How do i convert it to a number so i can do the date9 after? Thank you very much!


Accepted Solutions
Solution
‎07-19-2016 02:19 PM
Super User
Posts: 17,868

Re: Text to Number (Dates)

Input(a.date, datetime20.)

View solution in original post


All Replies
Super User
Posts: 17,868

Re: Text to Number (Dates)

Your INPUT requires the correct informat which would be a date time format, not 12.

 

Try datetime20.

 

I'm assuming you used proc import to import your data? If so, it guesses what type/format should be, obviously not correctly always. 

 

If you have a text file you can customize your import using a data step so it's read in correctly. Unfortunately Excel doesn't play well with others and there isn't an easy way to specify types when importing from an Excel file. You can look into DBSASTYPE if you'd like to explore that route. 

Contributor
Posts: 26

Re: Text to Number (Dates)

where would i put the datetime20.. what would be the query?

 

I import manually.. so i go to file -> Import data -> etc.

Contributor
Posts: 26

Re: Text to Number (Dates)

right now i just have 

 

proc sql;

create table test1.discovery

select 

A.field,

A. region

input(A.date1,12.0) as

from test1.location

;

 

i tried this before but didnt work...

 

datepart(input(A.date1,12.0))

Solution
‎07-19-2016 02:19 PM
Super User
Posts: 17,868

Re: Text to Number (Dates)

Input(a.date, datetime20.)

Super Contributor
Posts: 268

Re: Text to Number (Dates)

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 351 views
  • 1 like
  • 3 in conversation