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

Hello,

I've a text variable that looks like this:

period
2019-01-01T15:00:00.0/2019-01-01T16:00:00.0
2019-01-01T16:00:00.0/2019-01-01T17:00:00.0

but I'd like to exclude first part of this text to the 2 new vars (date in yymmdd10. format and hour as intg) like bellow:

period date hour
2019-01-01T15:00:00.0/2019-01-01T16:00:00.0 2019-01-01 15
2019-01-01T16:00:00.0/2019-01-01T17:00:00.0 2019-01-01 16

How can I achieve this one?

1 ACCEPTED SOLUTION

Accepted Solutions
PatrykSAS
Obsidian | Level 7

Ok, I've done simple substr and it works

input(substr(t1.__Observation_period,1,10),yymmdd10.)

View solution in original post

2 REPLIES 2
PatrykSAS
Obsidian | Level 7

Ok, I've done simple substr and it works

input(substr(t1.__Observation_period,1,10),yymmdd10.)

ballardw
Super User

The E8601DTw.d informat will read those values into a single datetime variable as well if of interest.

 

You might also test what happens without the Substr and just use

input(t1.__Observation_period,yymmdd10.)

 

The length on an informat controls how many characters are read. This is "nice" data where the first 10 characters are in a common layout, no 1 digit month or day of month values.

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!

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