BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SurajChand
Obsidian | Level 7

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

Server_Name=scan(Table_Names, 1, '');
CASLIB_Name=scan(Table_Names, 2, '');
Table_Name=scan(Table_Names, 3, '');
Table_State=scan(Table_Names,-1);
 
SurajChand_0-1717586338505.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
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;

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

What is wrong with the result? It seems perfectly correct to me, based upon the code you wrote. What result are you expecting?

--
Paige Miller
SurajChand
Obsidian | Level 7
I want Table_Name column should have full table name instead of some portion
Expected result
_[ 0680 ] تقرير عدد البلاغات بناء على الشخص
Current result
_[
PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
SurajChand
Obsidian | Level 7
I appreciate your statement, but I'm SAS Administrator and I found some example online so I tried. Please accept the apology!!
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Ksharp
Super User
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;

sas-innovate-white.png

Register Today!

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.

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1334 views
  • 0 likes
  • 4 in conversation