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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.