BookmarkSubscribeRSS Feed
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

 

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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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