BookmarkSubscribeRSS Feed
SASdevAnneMarie
Barite | Level 11

Hello Experts,

 

I would like to scan all the phrase after 5 space. 

I have this code : Ligne2 = scan(ligne,5,'') , but as result I have only one word.

 

Do you know please, how to scan all phrase after 5st space ?

 

Thank you for your help !

3 REPLIES 3
Reeza
Super User
LIGNE2 = substr(ligne, 5);

SUBSTR() will extract everything from the 5th character onwards. 

 

SCAN() with 5, looks for 5th term with a delimiter (space). Given your stated requirements I think SUBSTR() is the correct function for you usage. 

 


@SASdevAnneMarie wrote:

Hello Experts,

 

I would like to scan all the phrase after 5 space. 

I have this code : Ligne2 = scan(ligne,5,'') , but as result I have only one word.

 

Do you know please, how to scan all phrase after 5st space ?

 

Thank you for your help !


 

Tom
Super User Tom
Super User

@SASdevAnneMarie wrote:

Hello Experts,

 

I would like to scan all the phrase after 5 space. 

I have this code : Ligne2 = scan(ligne,5,'') , but as result I have only one word.

 

Do you know please, how to scan all phrase after 5st space ?

 

Thank you for your help !


Scan does return ALL.  It returns the nTH term.

1    data _null_;
2      line = 'one  two  three four five six seven';
3      line2 = scan(line,5,' ');
4      put (line line2) (=$quote.);
5    run;

line="one  two  three four five six seven" line2="five"

If you want the result to be "five six seven" then use CALL SCAN() and SUBSTRN().

6    data _null_;
7      line = 'one  two  three four five six seven';
8      call scan(line,5,position,length,' ');
9      line2=substrn(line,position);
10     put (line line2) (=$quote.);
11   run;

line="one  two  three four five six seven" line2="five six seven"

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 264 views
  • 2 likes
  • 4 in conversation