Hi everyone,
I currently have this variable whit these observations:
Date_time
20190909T080000+0000
20190909T081222+0000
20190909T081222+0000
etc..
I don't need the letter T and whatever is after it. I just need what is before it and keep it as a date (here 09/09/2019). The current format is B8601DZ35.
Anyone can help me with that? 🙂
Thanks!
I think of two ways. One is to use SCAN() function and another is to assign to a string of length 8 (under assumption that 'T' precedes 8 characters).
The first is:
data _null_;
input x $20.;
length y $8.;
y = scan(x, 1, 'T');
put y =;
datalines;
20190909T080000+0000
20190909T081222+0000
20190909T081222+0000
;
run;
The second is:
data _null_;
input x $20.;
length y $8.;
y = x;
put y=;
datalines;
20190909T080000+0000
20190909T081222+0000
20190909T081222+0000
;
run;
I think of two ways. One is to use SCAN() function and another is to assign to a string of length 8 (under assumption that 'T' precedes 8 characters).
The first is:
data _null_;
input x $20.;
length y $8.;
y = scan(x, 1, 'T');
put y =;
datalines;
20190909T080000+0000
20190909T081222+0000
20190909T081222+0000
;
run;
The second is:
data _null_;
input x $20.;
length y $8.;
y = x;
put y=;
datalines;
20190909T080000+0000
20190909T081222+0000
20190909T081222+0000
;
run;
Thanks for your help! I'll try that
If you variable type is character then you can use SCAN().
If your variable type is numeric with a date time format, then you want to use DATEPART().
@Antoine44 wrote:
Hi everyone,
I currently have this variable whit these observations:
Date_time
20190909T080000+0000
20190909T081222+0000
20190909T081222+0000
etc..
I don't need the letter T and whatever is after it. I just need what is before it and keep it as a date (here 09/09/2019). The current format is B8601DZ35.
Anyone can help me with that? 🙂
Thanks!
If the variable has the B8601DZ35. format attached to it then it must be a numeric variable that contains datetime values (number of seconds since 1960). You could just attach a different format so that it only prints the date. For example you could use the DTDATE9. format. Or you could extract just the date value (number of days since 1960) using the DATEPART() function and then attach any of the many formats that can display date values, for example DATE9. or YYMMDD10..
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.