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
;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.