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
;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.