<?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: Reading dynamic SAS dataset from directory path in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-dynamic-SAS-dataset-from-directory-path/m-p/465968#M118872</link>
    <description>&lt;P&gt;Thanks for the reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data ticker_files;&lt;BR /&gt;length XYZ_ABC_SAS $256.;&lt;BR /&gt;infile 'E:/xxxx/xxxx/&lt;SPAN&gt;XYZ&lt;/SPAN&gt;&lt;SPAN&gt;_&lt;/SPAN&gt;&lt;SPAN&gt;ABC&lt;/SPAN&gt;&lt;SPAN&gt;_&lt;/SPAN&gt;&lt;SPAN&gt;SAS&lt;/SPAN&gt;.sas7bdat'&lt;BR /&gt;FILENAME=&lt;SPAN&gt;XYZ&lt;/SPAN&gt;&lt;SPAN&gt;_&lt;/SPAN&gt;&lt;SPAN&gt;ABC&lt;/SPAN&gt;&lt;SPAN&gt;_&lt;/SPAN&gt;&lt;SPAN&gt;SAS&lt;/SPAN&gt;&lt;BR /&gt;DELIMITER=','&lt;BR /&gt;FIRSTOBS=1;&lt;BR /&gt;put &lt;SPAN&gt;XYZ&lt;/SPAN&gt;&lt;SPAN&gt;_&lt;/SPAN&gt;&lt;SPAN&gt;ABC&lt;/SPAN&gt;&lt;SPAN&gt;_&lt;/SPAN&gt;&lt;SPAN&gt;SAS&lt;/SPAN&gt;;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;ticker = scan(&lt;SPAN&gt;XYZ&lt;/SPAN&gt;&lt;SPAN&gt;_&lt;/SPAN&gt;&lt;SPAN&gt;ABC&lt;/SPAN&gt;&lt;SPAN&gt;_&lt;/SPAN&gt;&lt;SPAN&gt;SAS&lt;/SPAN&gt;,-2,'_');&lt;BR /&gt;output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this works fine when the name is&amp;nbsp; "&lt;SPAN&gt;XYZ&lt;/SPAN&gt;&lt;SPAN&gt;_&lt;/SPAN&gt;&lt;SPAN&gt;ABC&lt;/SPAN&gt;&lt;SPAN&gt;_&lt;/SPAN&gt;&lt;SPAN&gt;SAS", but when the name changes the code fails because the file name in the code is not dynamic.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please provide a solution with example code.&lt;/P&gt;</description>
    <pubDate>Wed, 30 May 2018 12:02:13 GMT</pubDate>
    <dc:creator>kamlesh_suthar</dc:creator>
    <dc:date>2018-05-30T12:02:13Z</dc:date>
    <item>
      <title>Reading dynamic SAS dataset from directory path</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-dynamic-SAS-dataset-from-directory-path/m-p/465965#M118870</link>
      <description>&lt;P&gt;Want to extract word from a dataset name, where the word is dynamic.&lt;/P&gt;&lt;P&gt;Example is below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Assume SAS dataset name is "XZY_ABC_SAS", from this I want to extract ABC and it should be stored in a variable, which can be called in wherever required.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Problem is SAS dataset name changes, i.e. next time it might be "XYZ_AGHJK_SAS", but the format remain same.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in Advance.&lt;/P&gt;</description>
      <pubDate>Wed, 30 May 2018 11:53:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-dynamic-SAS-dataset-from-directory-path/m-p/465965#M118870</guid>
      <dc:creator>kamlesh_suthar</dc:creator>
      <dc:date>2018-05-30T11:53:09Z</dc:date>
    </item>
    <item>
      <title>Re: Reading dynamic SAS dataset from directory path</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-dynamic-SAS-dataset-from-directory-path/m-p/465967#M118871</link>
      <description>&lt;P&gt;Meta-information about datasets can be taken from dictionary.tables in proc sql.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To extract substrings when delimiters are present, use the scan() function.&lt;/P&gt;</description>
      <pubDate>Wed, 30 May 2018 11:57:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-dynamic-SAS-dataset-from-directory-path/m-p/465967#M118871</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-05-30T11:57:31Z</dc:date>
    </item>
    <item>
      <title>Re: Reading dynamic SAS dataset from directory path</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-dynamic-SAS-dataset-from-directory-path/m-p/465968#M118872</link>
      <description>&lt;P&gt;Thanks for the reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data ticker_files;&lt;BR /&gt;length XYZ_ABC_SAS $256.;&lt;BR /&gt;infile 'E:/xxxx/xxxx/&lt;SPAN&gt;XYZ&lt;/SPAN&gt;&lt;SPAN&gt;_&lt;/SPAN&gt;&lt;SPAN&gt;ABC&lt;/SPAN&gt;&lt;SPAN&gt;_&lt;/SPAN&gt;&lt;SPAN&gt;SAS&lt;/SPAN&gt;.sas7bdat'&lt;BR /&gt;FILENAME=&lt;SPAN&gt;XYZ&lt;/SPAN&gt;&lt;SPAN&gt;_&lt;/SPAN&gt;&lt;SPAN&gt;ABC&lt;/SPAN&gt;&lt;SPAN&gt;_&lt;/SPAN&gt;&lt;SPAN&gt;SAS&lt;/SPAN&gt;&lt;BR /&gt;DELIMITER=','&lt;BR /&gt;FIRSTOBS=1;&lt;BR /&gt;put &lt;SPAN&gt;XYZ&lt;/SPAN&gt;&lt;SPAN&gt;_&lt;/SPAN&gt;&lt;SPAN&gt;ABC&lt;/SPAN&gt;&lt;SPAN&gt;_&lt;/SPAN&gt;&lt;SPAN&gt;SAS&lt;/SPAN&gt;;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;ticker = scan(&lt;SPAN&gt;XYZ&lt;/SPAN&gt;&lt;SPAN&gt;_&lt;/SPAN&gt;&lt;SPAN&gt;ABC&lt;/SPAN&gt;&lt;SPAN&gt;_&lt;/SPAN&gt;&lt;SPAN&gt;SAS&lt;/SPAN&gt;,-2,'_');&lt;BR /&gt;output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this works fine when the name is&amp;nbsp; "&lt;SPAN&gt;XYZ&lt;/SPAN&gt;&lt;SPAN&gt;_&lt;/SPAN&gt;&lt;SPAN&gt;ABC&lt;/SPAN&gt;&lt;SPAN&gt;_&lt;/SPAN&gt;&lt;SPAN&gt;SAS", but when the name changes the code fails because the file name in the code is not dynamic.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please provide a solution with example code.&lt;/P&gt;</description>
      <pubDate>Wed, 30 May 2018 12:02:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-dynamic-SAS-dataset-from-directory-path/m-p/465968#M118872</guid>
      <dc:creator>kamlesh_suthar</dc:creator>
      <dc:date>2018-05-30T12:02:13Z</dc:date>
    </item>
    <item>
      <title>Re: Reading dynamic SAS dataset from directory path</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-dynamic-SAS-dataset-from-directory-path/m-p/465972#M118873</link>
      <description>&lt;P&gt;This code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ticker_files;
length XYZ_ABC_SAS $256.;
infile 'E:/xxxx/xxxx/XYZ_ABC_SAS.sas7bdat'
FILENAME=XYZ_ABC_SAS
DELIMITER=','
FIRSTOBS=1;
put XYZ_ABC_SAS;


ticker = scan(XYZ_ABC_SAS,-2,'_');
output;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;has several issues.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, a .sas7bdat file is usually a dataset file and CANNOT be read (in a way that makes sense for youu) with infile/input.&lt;/P&gt;
&lt;P&gt;Define a libname for E:/xxxx/xxxx and use the dataset name in a set statement.&lt;/P&gt;
&lt;P&gt;The filename= option in the infile statement only makes sense when you use a list of filenames or wildcards, so that there's a need to know the current filename. With only one infile, this is not necessary, as the name is already known.&lt;/P&gt;</description>
      <pubDate>Wed, 30 May 2018 12:13:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-dynamic-SAS-dataset-from-directory-path/m-p/465972#M118873</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-05-30T12:13:47Z</dc:date>
    </item>
    <item>
      <title>Re: Reading dynamic SAS dataset from directory path</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-dynamic-SAS-dataset-from-directory-path/m-p/465974#M118875</link>
      <description>&lt;P&gt;Assign a library with the location for your datasets and then use dictionary.tables to find the tables in that location. If&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;LIBNAME MYWORK "\user\&amp;lt;your dataset location&amp;gt;";&lt;BR /&gt;proc sql;&lt;BR /&gt;select * INTO:DS&lt;BR /&gt;from dictionary.tables&lt;BR /&gt;where libname="MYWORK" and memname like 'XYZ_%_SAS'&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;%PUT "&amp;amp;DS";&lt;/PRE&gt;
&lt;P&gt;NOTE: If you have multiple datasets like 'XYZ_%_SAS' then you need to adopt to distinguish the datasets, maybe date stamp for the dataset.&lt;/P&gt;</description>
      <pubDate>Wed, 30 May 2018 12:11:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-dynamic-SAS-dataset-from-directory-path/m-p/465974#M118875</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-05-30T12:11:59Z</dc:date>
    </item>
    <item>
      <title>Re: Reading dynamic SAS dataset from directory path</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-dynamic-SAS-dataset-from-directory-path/m-p/465977#M118876</link>
      <description>&lt;P&gt;Here an example that &lt;EM&gt;might&lt;/EM&gt; make sense for what I &lt;EM&gt;think&lt;/EM&gt; you want to do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname mylib 'E:/xxxx/xxxx';

proc sql;
create table my_datasets as
select scan(memname,2,'_') as ticker
from dictionary.tables
where libname = 'MYLIB' and substr(memname,1,3 = 'XYZ');
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 May 2018 12:18:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-dynamic-SAS-dataset-from-directory-path/m-p/465977#M118876</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-05-30T12:18:16Z</dc:date>
    </item>
    <item>
      <title>Re: Reading dynamic SAS dataset from directory path</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-dynamic-SAS-dataset-from-directory-path/m-p/465993#M118881</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Well done on trying some code. It looks like you are fairly new to SAS programming so you might benefit from the free course provided by SAS "SAS Programming 1: Essentials" which can be found at:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://support.sas.com/edu/schedules.html?ctry=us&amp;amp;crs=PROG1" target="_blank"&gt;https://support.sas.com/edu/schedules.html?ctry=us&amp;amp;crs=PROG1&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The main SAS training site is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/training/" target="_blank"&gt;http://support.sas.com/training/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Wed, 30 May 2018 13:12:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-dynamic-SAS-dataset-from-directory-path/m-p/465993#M118881</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2018-05-30T13:12:40Z</dc:date>
    </item>
    <item>
      <title>Re: Reading dynamic SAS dataset from directory path</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-dynamic-SAS-dataset-from-directory-path/m-p/466055#M118887</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/83078"&gt;@SuryaKiran&lt;/a&gt;, SQL looks useful in this situation, as also suggested by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;, but remember to select the specific column you want to be saved in the &lt;FONT face="courier new,courier"&gt;into&lt;/FONT&gt; macro variable (in this case &lt;FONT face="courier new,courier"&gt;memname&lt;/FONT&gt;).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is also useful to know about the &lt;FONT face="courier new,courier"&gt;escape&lt;/FONT&gt; syntax as the underscore ('_') will match any single character with the like operator:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/sqlproc/63043/HTML/default/viewer.htm#n1ege2983n6h0vn1s1uj1459phr9.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/sqlproc/63043/HTML/default/viewer.htm#n1ege2983n6h0vn1s1uj1459phr9.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Wed, 30 May 2018 14:30:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-dynamic-SAS-dataset-from-directory-path/m-p/466055#M118887</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2018-05-30T14:30:46Z</dc:date>
    </item>
  </channel>
</rss>

