<?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 Extract the String from the File Path location dynamically in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-String-from-the-File-Path-location-dynamically/m-p/839040#M331736</link>
    <description>&lt;P&gt;I am having trouble&amp;nbsp; to do extraction of&amp;nbsp; 'String' from the folder path. How I can do it dynamically. Here is the example. I given two paths links with little modification. I got stuck after the following.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;path1: &lt;FONT color="#0000FF"&gt;Desktop\documents\school\class10\Grades\2022-10\expelled\&lt;/FONT&gt;&lt;BR /&gt;path2 :&lt;FONT color="#0000FF"&gt; Desktop\archive\documents\school\class102\Grades\2021-09\success\&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data link;
path1= 'Desktop\documents\school\classx\Grades\2022-10\expelled\';
xx = find(path1,'school');
folder = compress(substr(path1,xx+7),'-');
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;My expectations is to extract dynamically from both paths :&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;Path1 :&amp;nbsp;&lt;FONT color="#0000FF"&gt;class10\Grades\202210&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;FONT color="#0000FF"&gt;&lt;FONT color="#000000"&gt;Path2 :&lt;/FONT&gt; class102\Grades\202109&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;Path length will be changes depending on the folders and file name, but strings after 'School' have the same number of subfolders. That means, the number &lt;FONT color="#0000FF"&gt;'\'&amp;nbsp; (backslash)&lt;/FONT&gt; will be same for both links after the 'School' even though&amp;nbsp;lengths are different. Thank you.&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 17 Oct 2022 19:14:28 GMT</pubDate>
    <dc:creator>SASuserlot</dc:creator>
    <dc:date>2022-10-17T19:14:28Z</dc:date>
    <item>
      <title>Extract the String from the File Path location dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-String-from-the-File-Path-location-dynamically/m-p/839040#M331736</link>
      <description>&lt;P&gt;I am having trouble&amp;nbsp; to do extraction of&amp;nbsp; 'String' from the folder path. How I can do it dynamically. Here is the example. I given two paths links with little modification. I got stuck after the following.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;path1: &lt;FONT color="#0000FF"&gt;Desktop\documents\school\class10\Grades\2022-10\expelled\&lt;/FONT&gt;&lt;BR /&gt;path2 :&lt;FONT color="#0000FF"&gt; Desktop\archive\documents\school\class102\Grades\2021-09\success\&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data link;
path1= 'Desktop\documents\school\classx\Grades\2022-10\expelled\';
xx = find(path1,'school');
folder = compress(substr(path1,xx+7),'-');
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;My expectations is to extract dynamically from both paths :&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;Path1 :&amp;nbsp;&lt;FONT color="#0000FF"&gt;class10\Grades\202210&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;FONT color="#0000FF"&gt;&lt;FONT color="#000000"&gt;Path2 :&lt;/FONT&gt; class102\Grades\202109&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;Path length will be changes depending on the folders and file name, but strings after 'School' have the same number of subfolders. That means, the number &lt;FONT color="#0000FF"&gt;'\'&amp;nbsp; (backslash)&lt;/FONT&gt; will be same for both links after the 'School' even though&amp;nbsp;lengths are different. Thank you.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2022 19:14:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-String-from-the-File-Path-location-dynamically/m-p/839040#M331736</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-10-17T19:14:28Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the String from the File Path location dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-String-from-the-File-Path-location-dynamically/m-p/839043#M331738</link>
      <description>&lt;P&gt;Can you explain why you are removing the class number and the hyphen?&amp;nbsp; Also why are you using only three of the sub-directories and not all of them?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input path $80.;
cards;
Desktop\documents\school\class10\Grades\2022-10\expelled\
Desktop\archive\documents\school\class102\Grades\2021-09\success\
;

data want;
  set have;
  location = findw(path,'school','/\');
  if location then subpath=substr(path,location+7);
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs                                  path                                   location                subpath

 1     Desktop\documents\school\class10\Grades\2022-10\expelled\               19       class10\Grades\2022-10\expelled\
 2     Desktop\archive\documents\school\class102\Grades\2021-09\success\       27       class102\Grades\2021-09\success\
&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Oct 2022 19:01:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-String-from-the-File-Path-location-dynamically/m-p/839043#M331738</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-10-17T19:01:49Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the String from the File Path location dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-String-from-the-File-Path-location-dynamically/m-p/839047#M331739</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;
&lt;P&gt;Sorry , I think I forgot add them&amp;nbsp; when I edited the link, corrected it now. Thanks for the code.. However I have additional request. I am looking to remove the string colored in red of subpath you created. I am only extracting few subdirectories because based on this I will be creating macro variables.&lt;/P&gt;
&lt;PRE&gt;class10\Grades\2022-10&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;\expelled\&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;I am expecting ' &lt;STRONG&gt;class10\Grades\2022-10&lt;/STRONG&gt;' ( I remove the the sting after the second '\' back slash in REVERS.)&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2022 20:30:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-String-from-the-File-Path-location-dynamically/m-p/839047#M331739</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-10-17T20:30:16Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the String from the File Path location dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-String-from-the-File-Path-location-dynamically/m-p/839052#M331742</link>
      <description>&lt;P&gt;So you just want the three sub-directories under SCHOOL.&lt;/P&gt;
&lt;P&gt;In that case use the E modifier on FINDW() to return the word instead of the character.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  location = findw(path,'school','\','e');
  if location then subpath=catx('\',scan(path,location+1,'\')
                                   ,scan(path,location+2,'\')
                                   ,scan(path,location+3,'\'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs                                  path                                   location            subpath

 1     Desktop\documents\school\class10\Grades\2022-10\expelled\                3       class10\Grades\2022-10
 2     Desktop\archive\documents\school\class102\Grades\2021-09\success\        4       class102\Grades\2021-09

&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Oct 2022 19:29:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-String-from-the-File-Path-location-dynamically/m-p/839052#M331742</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-10-17T19:29:41Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the String from the File Path location dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-String-from-the-File-Path-location-dynamically/m-p/839054#M331743</link>
      <description>&lt;P&gt;Thanks you very much, What the argument 'e' do in Findw statement?&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2022 19:35:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-String-from-the-File-Path-location-dynamically/m-p/839054#M331743</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-10-17T19:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the String from the File Path location dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-String-from-the-File-Path-location-dynamically/m-p/839071#M331751</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/350312"&gt;@SASuserlot&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks you very much, What the argument 'e' do in Findw statement?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Exactly what I said it does.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;return the word instead of the character&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Look at the value of LOCATION in the two examples I posted.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2022 20:33:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-String-from-the-File-Path-location-dynamically/m-p/839071#M331751</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-10-17T20:33:12Z</dc:date>
    </item>
  </channel>
</rss>

