BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Shoref_Rahman
Calcite | Level 5

Hi,

Hi,

 

I currently have a list of dates that are in character format

 

14012018
15012018
15012018
16012018
16012018
18012018

 

 

In order to perform calculations I need these in date format, I want it to look like below and be in date format.

 

14/01/2018
15/01/2018
15/01/2018
16/01/2018
16/01/2018
18/01/2018

 

Thanks,

 

S

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data have_char_date;
input char_date $10.;
cards;
14012018
15012018
15012018
16012018
16012018
18012018
;

data want_num_sas_date;
set have_char_date;
want_num_sas_date=input(char_date,ddmmyy10.);
format want_num_sas_date ddmmyy10.;
run;

proc contents data=want_num_sas_date;
run;

View solution in original post

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Dates, times, datetimes are all numerics.  Dates is number of days since cuttoff, times number of seconds since midnight.

To convert text to number we use the input() function (as opposed to the put() function to go from number to character).  This is:
input(<text>,<format>)

So text can be any string, and format is one of the informats supplied by SAS or built by yourself - all in the documentation.

So:

data want;
  set have;
  num_date=input(char_date,ddmmyy8.);
  format num_date date9.;
run;
novinosrin
Tourmaline | Level 20
data have_char_date;
input char_date $10.;
cards;
14012018
15012018
15012018
16012018
16012018
18012018
;

data want_num_sas_date;
set have_char_date;
want_num_sas_date=input(char_date,ddmmyy10.);
format want_num_sas_date ddmmyy10.;
run;

proc contents data=want_num_sas_date;
run;

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
  • 556 views
  • 2 likes
  • 3 in conversation