<?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: Add variable based on import file name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Add-variable-based-on-import-file-name/m-p/418319#M102757</link>
    <description>&lt;P&gt;FILEVAR option on the INFILE statement. See example 5 in the documentation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=n1rill4udj0tfun1fvce3j401plo.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=n1rill4udj0tfun1fvce3j401plo.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And older walk through&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/techsup/technote/ts581.pdf" target="_blank"&gt;https://support.sas.com/techsup/technote/ts581.pdf&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;Another option:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-do-I-write-a-macro-to-import-multiple-text-files-that-have/ta-p/223627" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-do-I-write-a-macro-to-import-multiple-text-files-that-have/ta-p/223627&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/180981"&gt;@dsm&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I have hundreds of comma delimited text files that have two&amp;nbsp;columns and hundreds of thousands of rows, Each file is named after the participant (e.g., 1, 3, 15, etc...). What I need is two-fold, and both may not be possible in the same step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd like to:&lt;/P&gt;
&lt;P&gt;1) batch import each file and&lt;/P&gt;
&lt;P&gt;2) create a new variable based on each file name. So, I'd like a variable called "subj" that has the value 1 in every row for file 1, and so on...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've searched around and can't find any information on creating a variable from the import filename. Any advice?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 04 Dec 2017 21:57:58 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-12-04T21:57:58Z</dc:date>
    <item>
      <title>Add variable based on import file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-variable-based-on-import-file-name/m-p/418318#M102756</link>
      <description>&lt;P&gt;I have hundreds of comma delimited text files that have two&amp;nbsp;columns and hundreds of thousands of rows, Each file is named after the participant (e.g., 1, 3, 15, etc...). What I need is two-fold, and both may not be possible in the same step.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to:&lt;/P&gt;&lt;P&gt;1) batch import each file and&lt;/P&gt;&lt;P&gt;2) create a new variable based on each file name. So, I'd like a variable called "subj" that has the value 1 in every row for file 1, and so on...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've searched around and can't find any information on creating a variable from the import filename. Any advice?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 21:55:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-variable-based-on-import-file-name/m-p/418318#M102756</guid>
      <dc:creator>dsm</dc:creator>
      <dc:date>2017-12-04T21:55:25Z</dc:date>
    </item>
    <item>
      <title>Re: Add variable based on import file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-variable-based-on-import-file-name/m-p/418319#M102757</link>
      <description>&lt;P&gt;FILEVAR option on the INFILE statement. See example 5 in the documentation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=n1rill4udj0tfun1fvce3j401plo.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=n1rill4udj0tfun1fvce3j401plo.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And older walk through&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/techsup/technote/ts581.pdf" target="_blank"&gt;https://support.sas.com/techsup/technote/ts581.pdf&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;Another option:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-do-I-write-a-macro-to-import-multiple-text-files-that-have/ta-p/223627" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-do-I-write-a-macro-to-import-multiple-text-files-that-have/ta-p/223627&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/180981"&gt;@dsm&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I have hundreds of comma delimited text files that have two&amp;nbsp;columns and hundreds of thousands of rows, Each file is named after the participant (e.g., 1, 3, 15, etc...). What I need is two-fold, and both may not be possible in the same step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd like to:&lt;/P&gt;
&lt;P&gt;1) batch import each file and&lt;/P&gt;
&lt;P&gt;2) create a new variable based on each file name. So, I'd like a variable called "subj" that has the value 1 in every row for file 1, and so on...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've searched around and can't find any information on creating a variable from the import filename. Any advice?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 21:57:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-variable-based-on-import-file-name/m-p/418319#M102757</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-12-04T21:57:58Z</dc:date>
    </item>
    <item>
      <title>Re: Add variable based on import file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-variable-based-on-import-file-name/m-p/418442#M102785</link>
      <description>&lt;P&gt;Do you want all this data combined into one dataset at the end (which if the data is the same would be the best method):&lt;/P&gt;
&lt;PRE&gt;data want (keep=fname a b);
  infile ".../*.csv" filename=fname;
  input a b;
run;&lt;/PRE&gt;
&lt;P&gt;If you want separate ones then, something like:&lt;/P&gt;
&lt;PRE&gt;filename tmp pipe 'dir ".../*.csv" /b';

data _null_;
  infile tmp dlm="¬";
  call execute(cats('data want',put(_n_,best.),'; infile "',_infile_,'"; input a b; run;'));
run;&lt;/PRE&gt;
&lt;P&gt;This would create wantX with X being incremental for each file - mainly to show how to do it.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2017 11:45:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-variable-based-on-import-file-name/m-p/418442#M102785</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-12-05T11:45:18Z</dc:date>
    </item>
    <item>
      <title>Re: Add variable based on import file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-variable-based-on-import-file-name/m-p/462220#M117641</link>
      <description>super helpful, thanks so much!</description>
      <pubDate>Mon, 14 May 2018 22:35:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-variable-based-on-import-file-name/m-p/462220#M117641</guid>
      <dc:creator>dsm</dc:creator>
      <dc:date>2018-05-14T22:35:31Z</dc:date>
    </item>
  </channel>
</rss>

