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

hi,

suppose I have the following:

name
srjg5483h (djfhtbv  fjfj ) (fhfh 183 f)
fjj8 (f)
fkk   999999

I would like is to create new columns for the text within the parentheses (whenever present) :

nameinfocode
srjg5483h (djfhtbv  fjfj ) (fhfh 183 f)djfhtbv  fjfjfhfh 183 f
fjj8 (f)f
fkk   999999

thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Steelers_In_DC
Barite | Level 11

This will give you your desired output:

data have;

infile cards dsd;

length name $50.;

input name $;

cards;

srjg5483h (djfhtbv  fjfj ) (fhfh 183 f)

fjj8 (f)

fkk   999999

;

run;

data want;

set have;

info = scan(name,2,'(,)');

code = scan(name,4,'(,)');

run;

View solution in original post

3 REPLIES 3
LinusH
Tourmaline | Level 20

Use scan with ( as delimiter.

Compress ) from the results.

Data never sleeps
Steelers_In_DC
Barite | Level 11

This will give you your desired output:

data have;

infile cards dsd;

length name $50.;

input name $;

cards;

srjg5483h (djfhtbv  fjfj ) (fhfh 183 f)

fjj8 (f)

fkk   999999

;

run;

data want;

set have;

info = scan(name,2,'(,)');

code = scan(name,4,'(,)');

run;

Ksharp
Super User


data have;
infile cards dsd;
length name $50.;
input name $;
cards;
srjg5483h (djfhtbv  fjfj ) (fhfh 183 f)
fjj8 (f)
fkk   999999
;
run;

proc sql;
select max(countc(name,'()'))/2 into : n separated by ' ' from have;
quit;
data want;
 set have;
 array x{*} $ 100 v1-v&n;
 do i=1 to &n ;
  x{i}=scan(name,i*2,'()','m');
 end;
 drop i;
 run;

Xia Keshan

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!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1166 views
  • 4 likes
  • 4 in conversation