- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
URL_FULL = scan(clause3, 2, ",");
URL = scan(url_full, 2, ":");
Or try URL = scan(clause3, 4, ",:");
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
URL_FULL = scan(clause3, 2, ",");
URL = scan(url_full, 2, ":");
Or try URL = scan(clause3, 4, ",:");
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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;