BookmarkSubscribeRSS Feed
Smitha9
Fluorite | Level 6

I have a dataset which has characters

Start                     Stop           Date          Number

06/23/2004   12/15/2020   20030704       1234456

I want to change this to numeric date format.

For,

start and stop: mm/dd/yyyy and

Date: yyyymmdd

Number: numeric

 

thanks in advance.

2 REPLIES 2
Tom
Super User Tom
Super User

If you have a string like '06/23/2004' you can convert it to an actual date using the INPUT() function with the MMDDYY10. informat specification.

If you have a number like 20,030,704 you can convert it to an actual date value by first using the PUT() function with the 8. or Z8. format specification to convert it to a string like '20030704' and then use the INPUT() function with the YYMMDD8. informat specification.

If you have date values you an attach the YYMMDDN8. format to them to have them display as strings the look like 20030704. 

 

If you want to convert date values to a number like 20,030,704 then first use the PUT() function with the YYMMDDN8. format and then use the INPUT() function with the 8. informat.

Shmuel
Garnet | Level 18
date  = input(start,mmddyy10.); /* start date given as char type */
format date mmddyy10.;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 343 views
  • 0 likes
  • 3 in conversation