Greeting of the day!
I have below column as demo_table which has a row like this, so when I'm using scan function to split them into separate columns then third column is not scanning properly.
cas-shared-default datascientst _[ 0680 ] تقرير عدد البلاغات بناء على الشخص unloaded
data have;
Table_Names="cas-shared-default datascientst _[ 0680 ] تقرير عدد البلاغات بناء على الشخص unloaded";
Server_Name=scan(Table_Names, 1, ' ');
CASLIB_Name=scan(Table_Names, 2, ' ');
call scan(Table_Names,3,p1,l1,' ');
call scan(Table_Names,-1,p2,l2,' ');
Table_Name=substr(Table_Names,p1,p2-p1);
Table_State=scan(Table_Names,-1, ' ');
drop p1 p2 l1 l2;
run;
What is wrong with the result? It seems perfectly correct to me, based upon the code you wrote. What result are you expecting?
@SurajChand wrote:
I want Table_Name column should have full table name instead of some portion
Expected result
_[ 0680 ] تقرير عدد البلاغات بناء على الشخص
Current result
_[
Please describe the logic that a programmer could use to determine that some spaces are to be used as separators between words but other spaces are not used that way. I am not asking for code, I am asking for words to explain this.
I think I figured out a solution
data have;
string='cas-shared-default datascientst _[ 0680 ] تقرير عدد البلاغات بناء على الشخص unloaded';
word1=scan(string,1,' ');
word2=scan(string,2,' ');
temp_word3=scan(string,3,' ');
where3=find(string,temp_word3,'t');
word4=scan(string,-1,' ');
where4=find(string,word4,'t');
word3=substr(string,where3,where4-where3-length(temp_word3)-1);
run;
In order for the above to be a correct answer, I have made a number of assumptions and decided upon a logic which may not be correct for other text strings that you have.
There is no SCAN statement in SAS. There is the SCAN function and the CALL SCAN subroutine.
data have;
Table_Names="cas-shared-default datascientst _[ 0680 ] تقرير عدد البلاغات بناء على الشخص unloaded";
Server_Name=scan(Table_Names, 1, ' ');
CASLIB_Name=scan(Table_Names, 2, ' ');
call scan(Table_Names,3,p1,l1,' ');
call scan(Table_Names,-1,p2,l2,' ');
Table_Name=substr(Table_Names,p1,p2-p1);
Table_State=scan(Table_Names,-1, ' ');
drop p1 p2 l1 l2;
run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
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.