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

Hi to all

My data:

data  have;

input string $40.;

datalines;

33_we#fff23BOB_TS=234623623624756_TOO

BOB_TS=57335623566654756BO

60pBOB_TS=343467364563423TOp_#

WWBOB_TS=2346752665634cc90

9789BOB_TS=9872363566756Alll

ldldBOB_TS=2340235674025634efrwe

;

run;

I want to extract first 10 digits after string 'BOB_TS=' (example:  have 60pBOB_TS=343467563423TOp_#  want 3434675634 )

Ca somebody help me with this?

Thank you in advance

Bob

1 ACCEPTED SOLUTION

Accepted Solutions
slchen
Lapis Lazuli | Level 10


data  have;
input string $40.;
num=substr(string,index(string,'=')+1,10);
datalines;
33_we#fff23BOB_TS=234623623624756_TOO
BOB_TS=57335623566654756BO
60pBOB_TS=343467364563423TOp_#
WWBOB_TS=2346752665634cc90
9789BOB_TS=9872363566756Alll
ldldBOB_TS=2340235674025634efrwe
;
run;

View solution in original post

5 REPLIES 5
slchen
Lapis Lazuli | Level 10


data  have;
input string $40.;
num=substr(string,index(string,'=')+1,10);
datalines;
33_we#fff23BOB_TS=234623623624756_TOO
BOB_TS=57335623566654756BO
60pBOB_TS=343467364563423TOp_#
WWBOB_TS=2346752665634cc90
9789BOB_TS=9872363566756Alll
ldldBOB_TS=2340235674025634efrwe
;
run;

bob021
Calcite | Level 5

Thank you very much

Working like a charm

Bob

Haikuo
Onyx | Level 15

Using PRX,

data  have;

input string $40.;

digits=prxchange('s/(.+)((?<=BOB_TS=)\d{10}?)(.+)/$2/io', 1,string);

datalines;

33_we#fff23BOB_TS=234623623624756_TOO

BOB_TS=57335623566654756BO

60pBOB_TS=343467364563423TOp_#

WWBOB_TS=2346752665634cc90

9789BOB_TS=9872363566756Alll

ldldBOB_TS=2340235674025634efrwe

;

run;

Regards,

Haikuo

Ksharp
Super User

Backward Match for Peal Regular Expression :

data  have;

input string $40.;

re = prxparse('/((?<=BOB_TS=)\d{10})/io');

if prxmatch(re,string) then want= prxposn(re,1,string);

datalines;

33_we#fff23BOB_TS=234623623624756_TOO

BOB_TS=57335623566654756BO

60pBOB_TS=343467364563423TOp_#

WWBOB_TS=2346752665634cc90

9789BOB_TS=9872363566756Alll

ldldBOB_TS=2340235674025634efrwe

;

run;

Xia Keshan

stat_sas
Ammonite | Level 13

data want;

set have;

bob=substr(string,find(string,'BOB_TS=')+7,10);

run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1004 views
  • 7 likes
  • 5 in conversation