Hi,
I am trying to extract only distinct date from the below character variable.
Example:
variable abc
has below values and wanted to extract only 3 below distinct dates.
final.case_20190712
final.incident_20190405
final.abcd_20190405
final.trans_tarn_20190406
final.incident
I
If the set of words is alpanumeric,
This deals with delim
data have;
input abc $30.;
cards;
final.case_20190712
final.incident_20190405
final.abcd_20190405
final.trans_tarn_20190406
final.incident
;
data want;
set have;
k=findc(abc,'_','b');
if k>0 then date=substr(abc,k+1);
drop k;
run;
If the set of words is alpanumeric,
This deals with delim
data have;
input abc $30.;
cards;
final.case_20190712
final.incident_20190405
final.abcd_20190405
final.trans_tarn_20190406
final.incident
;
data want;
set have;
k=findc(abc,'_','b');
if k>0 then date=substr(abc,k+1);
drop k;
run;
@shuchidxt_gmail_com Oh you want distinct dates
proc sql;
create table want as
select distinct ifc(findc(abc,'_','b')>0,substr(abc,findc(abc,'_','b')+1),' ') as dates
from have
having dates>' ';
quit;
Thanks All. it worked
Just for fun.
data have;
input abc $30.;
temp=scan(abc,-1,'_');
if prxmatch('/^\d{8}$/',strip(temp)) then want=temp;
cards;
final.case_20190712
final.incident_20190405
final.abcd_20190405
final.trans_tarn_20190406
final.incident
;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: