<?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: append many files and add a new variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/append-many-files-and-add-a-new-variable/m-p/143733#M28727</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;ADD to KEEP STATMENT:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data all;&lt;/P&gt;&lt;P&gt;set allinj: indsname=src_file;&lt;/P&gt;&lt;P&gt;excel_file=src_file;&lt;/P&gt;&lt;P&gt;keep clm_num doi x excel;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 16 Sep 2014 16:34:05 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2014-09-16T16:34:05Z</dc:date>
    <item>
      <title>append many files and add a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/append-many-files-and-add-a-new-variable/m-p/143728#M28722</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The code below brings in many excel files from a folder (they all contain the same variables).&lt;/P&gt;&lt;P&gt;All the observations in the variable named "dataset" begin with "allinj" and are followed by numbers (eg allinj82614, allinj23014, allinj51614, etc)&lt;/P&gt;&lt;P&gt;I would like to append the files into one file and keep three variables (ie clm_num, doi, x).&lt;/P&gt;&lt;P&gt;Also, I need to add a variable into this new file that contains the variable dataset (eg allinj82614, allinj23014, allinj51614) so that it's known which excel file the data came from.&lt;/P&gt;&lt;P&gt;Does anyone know how to do this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;filename dir&amp;nbsp; "C:\Users\Desktop\Test_Import\*.xls ";&lt;/P&gt;&lt;P&gt;data new;&lt;/P&gt;&lt;P&gt;&amp;nbsp; length filename&amp;nbsp; fname $ 100;&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile dir&amp;nbsp; eof=last filename=fname;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input ; &lt;/P&gt;&lt;P&gt;&amp;nbsp; last: filename=fname;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data a;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set new;&lt;/P&gt;&lt;P&gt;&amp;nbsp; call scan(filename,6,pos3,len,'\');&lt;/P&gt;&lt;P&gt;&amp;nbsp; drop len;&lt;/P&gt;&lt;P&gt;&amp;nbsp; filename1=substr(filename,pos3);&lt;/P&gt;&lt;P&gt;&amp;nbsp; dataset=compress(filename1,"\-_."); &lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set a;&lt;/P&gt;&lt;P&gt;&amp;nbsp; call execute('proc import datafile="C:\Users\Desktop\Test_Import\'||strip(filename1)||'" out='||strip(dataset)||';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Sep 2014 23:19:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/append-many-files-and-add-a-new-variable/m-p/143728#M28722</guid>
      <dc:creator>gzr2mz39</dc:creator>
      <dc:date>2014-09-12T23:19:44Z</dc:date>
    </item>
    <item>
      <title>Re: append many files and add a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/append-many-files-and-add-a-new-variable/m-p/143729#M28723</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If all the files contain the same variables then you can use the indsname option. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data all;&lt;/P&gt;&lt;P&gt;set allinj: indsname=src_file;&lt;/P&gt;&lt;P&gt;excel_file=src_file;&lt;/P&gt;&lt;P&gt;keep clm_num doi x;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Sep 2014 23:48:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/append-many-files-and-add-a-new-variable/m-p/143729#M28723</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-09-12T23:48:26Z</dc:date>
    </item>
    <item>
      <title>Re: append many files and add a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/append-many-files-and-add-a-new-variable/m-p/143730#M28724</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Reeza,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Do you also know how to add a variable into this new file that contains the variable "dataset" (eg allinj82614, allinj23014, allinj51614) so that it's clear which excel file the data came from?&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Sep 2014 17:19:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/append-many-files-and-add-a-new-variable/m-p/143730#M28724</guid>
      <dc:creator>gzr2mz39</dc:creator>
      <dc:date>2014-09-15T17:19:47Z</dc:date>
    </item>
    <item>
      <title>Re: append many files and add a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/append-many-files-and-add-a-new-variable/m-p/143731#M28725</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just add &lt;STRONG&gt;excel_file&lt;/STRONG&gt; to the &lt;STRONG&gt;keep&lt;/STRONG&gt; statement in Reeza's code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Sep 2014 17:39:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/append-many-files-and-add-a-new-variable/m-p/143731#M28725</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2014-09-15T17:39:40Z</dc:date>
    </item>
    <item>
      <title>Re: append many files and add a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/append-many-files-and-add-a-new-variable/m-p/143732#M28726</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sir.if possible explain with a detailed example it would help me.I am a beginner.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Sep 2014 06:36:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/append-many-files-and-add-a-new-variable/m-p/143732#M28726</guid>
      <dc:creator>venkatnaveen</dc:creator>
      <dc:date>2014-09-16T06:36:48Z</dc:date>
    </item>
    <item>
      <title>Re: append many files and add a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/append-many-files-and-add-a-new-variable/m-p/143733#M28727</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;ADD to KEEP STATMENT:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data all;&lt;/P&gt;&lt;P&gt;set allinj: indsname=src_file;&lt;/P&gt;&lt;P&gt;excel_file=src_file;&lt;/P&gt;&lt;P&gt;keep clm_num doi x excel;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Sep 2014 16:34:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/append-many-files-and-add-a-new-variable/m-p/143733#M28727</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-09-16T16:34:05Z</dc:date>
    </item>
    <item>
      <title>Re: append many files and add a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/append-many-files-and-add-a-new-variable/m-p/143734#M28728</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;The kind of documentation that would always be required.:&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;/* Create a dataset called &lt;EM&gt;all&lt;/EM&gt; */&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;data all;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;/* Read all datasets with names starting with &lt;EM&gt;allinj&lt;/EM&gt;. Create a variable called &lt;EM&gt;src_file&lt;/EM&gt; that will hold the actual name of the dataset being read. */&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;set allinj: indsname=src_file;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;/* Copy the name of the dataset being read to a variable called &lt;EM&gt;excel_file&lt;/EM&gt; */&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;excel_file=src_file;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;/* List the names of variables which will be part of the &lt;EM&gt;all&lt;/EM&gt; dataset */&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;keep clm_num doi x excel_file;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Sep 2014 17:35:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/append-many-files-and-add-a-new-variable/m-p/143734#M28728</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2014-09-16T17:35:06Z</dc:date>
    </item>
  </channel>
</rss>

