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

Hi, I'm trying to find the position of where the second "," is

 

For example, this is my data and code:

 

data test2;
clause3="[Type:File, URL :websitedomainname , Version :21 , Status :done , Date :01JUN2021 Notes :none" ;

n2=index(upcase(clause3),'URL :');
n3=index(clause3,', Version');
if n2>0 then do;
URL=substr(clause3,n2, n3);
output;
end;
run;

 

I want to take whatever is after URL: and create it as it's own variable. However, I want it to only take "websitedomainname "...so how do i find the position of the comma after .com so i can apply that position in my substr function. 

Currently, this is what i'm getting 

 

n2      n3     URL

13      35     URL :websitedomainname  , Version :21

 

What i would like is 

 

n2      n3     URL

                  websitedomainname  

 

Your help is greatly appreciated. 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
Have you considered the SCAN function instead?

URL_FULL = scan(clause3, 2, ",");
URL = scan(url_full, 2, ":");

Or try URL = scan(clause3, 4, ",:");

View solution in original post

2 REPLIES 2
Reeza
Super User
Have you considered the SCAN function instead?

URL_FULL = scan(clause3, 2, ",");
URL = scan(url_full, 2, ":");

Or try URL = scan(clause3, 4, ",:");

ballardw
Super User

@Dregerator wrote:

Hi, I'm trying to find the position of where the second "," is

 

For example, this is my data and code:

 

data test2;
clause3="[Type:File, URL :websitedomainname , Version :21 , Status :done , Date :01JUN2021 Notes :none" ;

n2=index(upcase(clause3),'URL :');
n3=index(clause3,', Version');
if n2>0 then do;
URL=substr(clause3,n2, n3);
output;
end;
run;

 

I want to take whatever is after URL: and create it as it's own variable. However, I want it to only take "websitedomainname "...so how do i find the position of the comma after .com so i can apply that position in my substr function. 

Currently, this is what i'm getting 

 

n2      n3     URL

13      35     URL :websitedomainname  , Version :21

 

What i would like is 

 

n2      n3     URL

                  websitedomainname  

 

Your help is greatly appreciated. 


Your question asks " how do i find the position of the comma after .com" which is different than "second comma". Plus, your example does not include ".com".

 

Find functions have an optional fourth parameter which is start position. So you could determine the position of the string ".com" and use that as the start position to find a comma.

This finds the first comma after the first time ".com" appears:

data example;
clause3="some text, other text, abc.com , text following .com" ;
commapostcom = findc(clause3,',','i',find(clause3,'.com','i'));
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 1176 views
  • 0 likes
  • 3 in conversation