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) :
| name | info | code |
|---|---|---|
| srjg5483h (djfhtbv fjfj ) (fhfh 183 f) | djfhtbv fjfj | fhfh 183 f |
| fjj8 (f) | f | |
| fkk 999999 |
thank you!
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;
Use scan with ( as delimiter.
Compress ) from the results.
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;
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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.