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

An example of the string is below, how do I remove the TXX:XX:XX+XX:XX part of the string. I want to make it as dynamic as possible. Examples of how the string may appear in my data. 


{"VariableA":"1","VaraibleB":"1","VariableC":"1","VariableD":"2023-01-02T13:30:10+00:00","VariableE":"1"}

{"VariableA":"1","VaraibleB":"1","VariableC":"1","VariableD":"","VariableE":"1"}

{"VariableA":"1","VaraibleB":"1","VariableD":"2023-01-02T13:30:10+00:00","VariableC":"1","VariableE":"1"}

 

cheers

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

A RegEx should do.

data have;
  infile datalines truncover;
  input have_str $300.;
  datalines4;
{"VariableA":"1","VaraibleB":"1","VariableC":"1","VariableD":"2023-01-02T13:30:10+00:00","VariableE":"1"}
{"VariableA":"1","VaraibleB":"1","VariableC":"1","VariableD":"","VariableE":"1"}
{"VariableA":"1","VaraibleB":"1","VariableD":"2023-01-02T13:30:10+00:00","VariableC":"1","VariableE":"1"}
;;;;

data want;
  set have;
  length want_str $300;
  want_str=prxchange('s/T\d\d:\d\d:\d\d\+\d\d:\d\d//oi',-1,trim(have_str));
run;

You can help us help you if you post sample data via a working SAS data step as done above with data have and then also show us a concrete desired result based on the sample data provided. 

View solution in original post

1 REPLY 1
Patrick
Opal | Level 21

A RegEx should do.

data have;
  infile datalines truncover;
  input have_str $300.;
  datalines4;
{"VariableA":"1","VaraibleB":"1","VariableC":"1","VariableD":"2023-01-02T13:30:10+00:00","VariableE":"1"}
{"VariableA":"1","VaraibleB":"1","VariableC":"1","VariableD":"","VariableE":"1"}
{"VariableA":"1","VaraibleB":"1","VariableD":"2023-01-02T13:30:10+00:00","VariableC":"1","VariableE":"1"}
;;;;

data want;
  set have;
  length want_str $300;
  want_str=prxchange('s/T\d\d:\d\d:\d\d\+\d\d:\d\d//oi',-1,trim(have_str));
run;

You can help us help you if you post sample data via a working SAS data step as done above with data have and then also show us a concrete desired result based on the sample data provided. 

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 574 views
  • 1 like
  • 2 in conversation