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