Hello,
Please find below data Have and data Want.
We would like to extract X1 from the data according to the following rules:
1. it appears after the last back slash in the sentence
2. and also before the first dot following this word (if there is a dot)
3. and this word contains only capital letters or under score in it (without small letters)
4. and there is no garbage after this word (such as '..')
5. if it can not find a word that follows all theses rules than write NOWORD
We would like to extract X2 from the data according to the following rules:
1. it appears always after this word BPS.STQR/ or this word BPS.STQR,
in other words it appears after BPS.STQR and is surrounded with '/' or with ','
Thanks in advance
----------------------------------------------------------------------------------------------
Data have ;
input data $60. ;
cards ;
data/dataflow/BPS.STQR/WAB/1.0/NER_PGTABC
data/dataflow/wow/BPS.STQR,WAB,1.0/NER_QZW
data/dataflow/wow/BPS.STQR,WAB,1.0/NER_QZW ..
data/dataflow/wow/BPS.STQR,WAB,1.0/NER_QZW.ABCDEFG
/availability/dataflow/*/*/*/*/-
/availability
;
Run ;
Data Want ;
input x1 $10. x2 $7. ;
cards ;
NER_PGTABC WAB
NER_QZW WAB
NER_QZW WAB
NER_QZW WAB
NOWORD
NOWORD
;
Run ;
data want;
set have;
location = find(data,'BPS.STQR');
if location>0 then x2=scan(substr(data,location+9),1);
run;
Hellow,
Seems I found a solution for calculating X1 - view data test:-
Would appreciate your help regarding X2..
Data test ;
set have ;
X1 = scan(scan(data,-1,"/"),1,'.') ;
if count(x1,lowcase(X1)) = 1 then X1 = 'NOWORD' ;
Run ;
A little clarification
The purpose is to clean the words from the garbage
as long as they have upercase or underscores.
Thanks
data want;
set have;
location = find(data,'BPS.STQR');
if location>0 then x2=scan(substr(data,location+9),1);
run;
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.