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

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! 

1 ACCEPTED SOLUTION

Accepted Solutions
KachiM
Rhodochrosite | Level 12

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;

 

View solution in original post

5 REPLIES 5
KachiM
Rhodochrosite | Level 12

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;

 

Antoine44
Fluorite | Level 6

Thanks for your help! I'll try that 

Reeza
Super User

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! 


 

Astounding
PROC Star
Since your new variable is supposed to be a date:

newvar = input(oldvar, yymmdd8.) ;
format newvar mmddyys10.;
Tom
Super User Tom
Super User

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..

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1051 views
  • 2 likes
  • 5 in conversation