I've one variable called CRE and it has value like MIN_[NDIP]_2. Now I want to filter only the values [NDIP] using substr function.
When I tried with the following, it's not producing the desired result. Any help?
substr(cre,5,length(cre)-2)
I want the result only using susbstr function.
@David_Billa wrote:
I've one variable called CRE and it has value like MIN_[NDIP]_2. Now I want to filter only the values [NDIP] using substr function.
When I tried with the following, it's not producing the desired result. Any help?
substr(cre,5,length(cre)-2)I want the result only using susbstr function.
Your arithmetic is wrong. You need also subtract the 4 characters you skipped by starting in column 5.
733 data test; 734 x='MIN_[NDIP]_2 '; 735 len=length(x); 736 want=substr(x,5,len-4-2); 737 put (_all_) (=/); 738 run; x=MIN_[NDIP]_2 len=12 want=[NDIP]
scan(cre, 2, "_")
What is the incorrect result that you are getting?
Can you provide a small portion of your data set following these instructions? Because obviously when you manually type a character string in a line of text, sometimes the full information is lost about what this character string really is (for example there may be non-printing characters).
I want the result only using susbstr function.
I reserve the right to give other answers, to propose simpler methods, especially for the benefit of others who might be reading along, and I think @PGStats has nailed it.
@David_Billa wrote:
I've one variable called CRE and it has value like MIN_[NDIP]_2. Now I want to filter only the values [NDIP] using substr function.
When I tried with the following, it's not producing the desired result. Any help?
substr(cre,5,length(cre)-2)I want the result only using susbstr function.
Your arithmetic is wrong. You need also subtract the 4 characters you skipped by starting in column 5.
733 data test; 734 x='MIN_[NDIP]_2 '; 735 len=length(x); 736 want=substr(x,5,len-4-2); 737 put (_all_) (=/); 738 run; x=MIN_[NDIP]_2 len=12 want=[NDIP]
@David_Billa wrote:
...
I want the result only using susbstr function.
Maxim 14.
Maxim 14.
Maxim 14.
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.