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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 548 views
  • 0 likes
  • 2 in conversation