BookmarkSubscribeRSS Feed
abparks_jl
Fluorite | Level 6

Hello! 

 

I am new to SAS VA and am stuck on something that seems like it should be simple but I cannot figure it out. I uploaded a data set and the date column was converted to a category instead of a measure. The date fields read like this: 

 

2021.04.19 9:03

2021.04.21 7:22

etc.

 

I am try to convert the data item to a measure so it can be treated as a date and formatted to DDMMYYYY. 

 

Anyone able to help me out? Thanks in advance! 

1 REPLY 1
adornodj
Obsidian | Level 7

Hello -  Try the code below.  Assuming your date field is called "date", you can create a new field called "date_want"  Basically, the input function will convert your data from character, to the numeric date field.  Since your data is currently in yyyy.mm.dd, we need to define that format for SAS with yymmdd10. (10 total characters, in yymmdd order).  the Scan function is taking all the records before the space, between your date and what looks like the time.  

 

data want;
set have;
date_want = input(scan(date,1," "),yymmdd10.);
format date_want mmddyy10.;
run;

 

RESULT

date date_want
2021.04.19 9:03 04/19/2021
2021.04.21 7:22 04/21/2021