BookmarkSubscribeRSS Feed
Dg112
Calcite | Level 5
My Data has the following date values in character variable type
Date
2013/12
2014/01
2014/02
2014/02
2012/06

How should I convert the variable type to numeric?
1 REPLY 1
Kurt_Bremser
Super User

Since you cannot change the type of a variable, you have to create a new one, which is done by doing the "rename-convert-drop" dance:

data have;
input date $7.;
datalines;
2013/12
2014/01
2014/02
2014/02
2012/06
;

data want;
set have (rename=(date=_date));
format date yymms7.;
date = input(compress(_date,"/"),yymmn6.);
drop _date;
run;

(SAS will automatically assume the first day of the month for the raw date values)

Alternatively, you can add the day yourself and use a complete date informat:

data want;
set have (rename=(date=_date));
format date yymms7.;
date = input(_date!!"/01",yymmdd10.);
drop _date;
run;

Or you can use the same method when initially bringing the data into SAS, which depends on the type of your data source.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 1 reply
  • 608 views
  • 0 likes
  • 2 in conversation