<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Return everything from the left of something in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Return-everything-from-the-left-of-something/m-p/359374#M84508</link>
    <description>&lt;P&gt;Very interesting question.&lt;/P&gt;
&lt;P&gt;You only want the position of most right '_' ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dsn=h1_1_final;
Data _null_;
       Us=count("&amp;amp;dsn.","_");
       Abv=substr("&amp;amp;dsn",1,findc("&amp;amp;dsn.","_",'b')-1);
put us= abv= ;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 17 May 2017 14:03:35 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2017-05-17T14:03:35Z</dc:date>
    <item>
      <title>Return everything from the left of something</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Return-everything-from-the-left-of-something/m-p/359039#M84431</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have this:&lt;/P&gt;&lt;P&gt;%let dsn=h1_1_final;&lt;/P&gt;&lt;P&gt;Data test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Us=count("&amp;amp;dsn.","_");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Abv=scan("&amp;amp;dsn.",us,"_");&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And i'm trying to end up with:&lt;/P&gt;&lt;P&gt;US=2&lt;/P&gt;&lt;P&gt;ABV=H1_1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, the code above is giving me:&lt;/P&gt;&lt;P&gt;US=2&lt;/P&gt;&lt;P&gt;ABV=1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't figure out the right combination of scan or count and substr and length or whatever to get abv=h1_1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas?&lt;BR /&gt;Thanks&lt;/P&gt;&lt;P&gt;M&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;EDIT: This code will be part of a macro that cycles through 20+ different dataset names, some with 1 underscore, some with 2, etc.&amp;nbsp; So i need it to be dynamic.&amp;nbsp; Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2017 14:23:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Return-everything-from-the-left-of-something/m-p/359039#M84431</guid>
      <dc:creator>MeganE</dc:creator>
      <dc:date>2017-05-16T14:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: Return everything from the left of something</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Return-everything-from-the-left-of-something/m-p/359069#M84434</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also use DATA Step functions in the macro language by using %SYSFUNC. The SCAN function returns "words" deilmited by some chars. For your example, check the position of the last underscore and use the %SUBSTR function. the negative number in the FIND function will search from right to left.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dsn = h1_1_final;

%let last_us = %sysfunc( find(&amp;amp;dsn, _, -256) );

%let first_part = %substr(&amp;amp;dsn, 1, %eval(&amp;amp;last_us -1));

%put NOTE: &amp;amp;=dsn &amp;amp;=last_us &amp;amp;=first_part;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 May 2017 14:49:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Return-everything-from-the-left-of-something/m-p/359069#M84434</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2017-05-16T14:49:16Z</dc:date>
    </item>
    <item>
      <title>Re: Return everything from the left of something</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Return-everything-from-the-left-of-something/m-p/359071#M84435</link>
      <description>&lt;P&gt;If you want everything up to the last underscore, you can use CALL SCAN.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dsn=h1_1_final;

Data test(drop=position length);
  Us=count("&amp;amp;dsn.","_");
  call scan("&amp;amp;dsn.",us,position,length,"_");
  abv=substr("&amp;amp;dsn.",1,position+length-1);
Run;

proc print data=test;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 May 2017 14:51:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Return-everything-from-the-left-of-something/m-p/359071#M84435</guid>
      <dc:creator>SuzanneDorinski</dc:creator>
      <dc:date>2017-05-16T14:51:36Z</dc:date>
    </item>
    <item>
      <title>Re: Return everything from the left of something</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Return-everything-from-the-left-of-something/m-p/359152#M84465</link>
      <description>&lt;P&gt;For what it is worth, can also just be one-liner:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	   abv=prxchange('s/(^[^_]+_[^_]+)(_[^_]+$|\s*$)/$1/', -1, "&amp;amp;dsn.");
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2017 18:39:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Return-everything-from-the-left-of-something/m-p/359152#M84465</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2017-05-16T18:39:37Z</dc:date>
    </item>
    <item>
      <title>Re: Return everything from the left of something</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Return-everything-from-the-left-of-something/m-p/359163#M84466</link>
      <description>&lt;P&gt;Also, FWIW, can be a one liner with something like:&lt;/P&gt;
&lt;PRE&gt;abv=substr("&amp;amp;dsn.",1,findc("&amp;amp;dsn.","_",-999)-1);&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2017 19:21:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Return-everything-from-the-left-of-something/m-p/359163#M84466</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-05-16T19:21:51Z</dc:date>
    </item>
    <item>
      <title>Re: Return everything from the left of something</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Return-everything-from-the-left-of-something/m-p/359374#M84508</link>
      <description>&lt;P&gt;Very interesting question.&lt;/P&gt;
&lt;P&gt;You only want the position of most right '_' ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dsn=h1_1_final;
Data _null_;
       Us=count("&amp;amp;dsn.","_");
       Abv=substr("&amp;amp;dsn",1,findc("&amp;amp;dsn.","_",'b')-1);
put us= abv= ;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2017 14:03:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Return-everything-from-the-left-of-something/m-p/359374#M84508</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-05-17T14:03:35Z</dc:date>
    </item>
  </channel>
</rss>

