<?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: Converting multiple files to Stata in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Converting-multiple-files-to-Stata/m-p/555599#M9701</link>
    <description>&lt;P&gt;1) The SAS code I have presented looks for all the SAS data sets (tables) in the "folder_sas_data" location that is in your code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) My code then creates a SAS program containing &lt;FONT face="courier new,courier"&gt;proc export&lt;/FONT&gt; statements for each and every SAS data set it found from step (1).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3) This generated code from (2) is written to a file. This file is referred to in my code with:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;file 'full-file-path.sas';&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4) The location and name of the file containing the &lt;FONT face="courier new,courier"&gt;proc export&lt;/FONT&gt; statements is up to you, as long as it ends in '.sas'. Whatever you decide upon should replace the&amp;nbsp;&lt;SPAN&gt;'full-file-path.sas', e.g. (depending upon whether your'e using Windows or Unix or Linux, etc.):&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;file 'c:\tmp\my_proc_export_code.sas';&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;5) Once the code I have posted completes (without issues - see SAS log), open your version of&amp;nbsp;'full-file-path.sas' in SAS and you should see all of the &lt;FONT face="courier new,courier"&gt;proc export&lt;/FONT&gt; statements - one per SAS data set.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;6) If you are happy with what you see then you can submit the &lt;FONT face="courier new,courier"&gt;proc export&lt;/FONT&gt; code, perhaps try the first one initially to see if there are any issues, then, if OK, the rest can be submitted in one go.&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;&lt;SPAN&gt;I hope that is clearer.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Please ask if you have any questions.&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;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Amir.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 02 May 2019 13:18:55 GMT</pubDate>
    <dc:creator>Amir</dc:creator>
    <dc:date>2019-05-02T13:18:55Z</dc:date>
    <item>
      <title>Converting multiple files to Stata</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-multiple-files-to-Stata/m-p/555584#M9698</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not a SAS user at all, so please I apology if my question is a bit stupid. I was given access to data in SAS format and I want to covert it to Stata (.dta), which is the software I am more comfortable with (btw, I cannot do it using the usesas command in Stata because the data is stored in a computed with no access to internet, so I am unable to download user-written commands).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can do it file by file, with the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname in 'folder_sas_data';
data temp;
set in.file_name;
proc export data=temp outfile='folder_stata_data/file_name.dta';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, there are thousands of files with different names that do not follow a clear pattern. Ideally I would like to access to all SAS files in the&amp;nbsp;folder_sas_data directory, and open each of them and export them in dta format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any clue on how can I do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 12:19:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-multiple-files-to-Stata/m-p/555584#M9698</guid>
      <dc:creator>alexia20</dc:creator>
      <dc:date>2019-05-02T12:19:59Z</dc:date>
    </item>
    <item>
      <title>Re: Converting multiple files to Stata</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-multiple-files-to-Stata/m-p/555591#M9699</link>
      <description>&lt;P&gt;No need to apologise if you don't know; at least you're trying. I'm not sure I see the need for &lt;FONT face="courier new,courier"&gt;data&lt;/FONT&gt; and the &lt;FONT face="courier new,courier"&gt;set&lt;/FONT&gt; statements, because you should be able to export all of the SAS data sets directly, without first having to copy them to a temp SAS data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following untested code makes use of SAS system's dictionary tables to get the names of the SAS data sets in library 'in' then from that it constructs the &lt;FONT face="courier new,courier"&gt;proc export&lt;/FONT&gt; statements and writes them out to a file for you to examine and then submit in SAS if you are happy with what you see. Note the comment to "replace 'full-file-path.sas'", the SAS code to run will be contained in there.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname in 'folder_sas_data';

/* replace 'full-file-path.sas' with a path and name of a file that will have SAS code written to it */
data _null_;
   file 'full-file-path.sas';

   set sashelp.vtable;

   where upcase(libname) eq 'IN';

   put "proc export data=in." memname "outfile='folder_stata_data/" memname +(-1) ".dta;";
   put 'run;';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Report back if you have any issues with the log showing the code and any errors, warnings, etc.&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>Thu, 02 May 2019 12:57:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-multiple-files-to-Stata/m-p/555591#M9699</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2019-05-02T12:57:22Z</dc:date>
    </item>
    <item>
      <title>Re: Converting multiple files to Stata</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-multiple-files-to-Stata/m-p/555593#M9700</link>
      <description>Sorry, I don't quite get what you mean by "replace 'full-file-path.sas'" comment. It's the path and name of a file with SAS code written to it, but what code exactly?&lt;BR /&gt;Thank you!</description>
      <pubDate>Thu, 02 May 2019 13:00:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-multiple-files-to-Stata/m-p/555593#M9700</guid>
      <dc:creator>alexia20</dc:creator>
      <dc:date>2019-05-02T13:00:11Z</dc:date>
    </item>
    <item>
      <title>Re: Converting multiple files to Stata</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-multiple-files-to-Stata/m-p/555599#M9701</link>
      <description>&lt;P&gt;1) The SAS code I have presented looks for all the SAS data sets (tables) in the "folder_sas_data" location that is in your code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) My code then creates a SAS program containing &lt;FONT face="courier new,courier"&gt;proc export&lt;/FONT&gt; statements for each and every SAS data set it found from step (1).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3) This generated code from (2) is written to a file. This file is referred to in my code with:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;file 'full-file-path.sas';&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4) The location and name of the file containing the &lt;FONT face="courier new,courier"&gt;proc export&lt;/FONT&gt; statements is up to you, as long as it ends in '.sas'. Whatever you decide upon should replace the&amp;nbsp;&lt;SPAN&gt;'full-file-path.sas', e.g. (depending upon whether your'e using Windows or Unix or Linux, etc.):&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;file 'c:\tmp\my_proc_export_code.sas';&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;5) Once the code I have posted completes (without issues - see SAS log), open your version of&amp;nbsp;'full-file-path.sas' in SAS and you should see all of the &lt;FONT face="courier new,courier"&gt;proc export&lt;/FONT&gt; statements - one per SAS data set.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;6) If you are happy with what you see then you can submit the &lt;FONT face="courier new,courier"&gt;proc export&lt;/FONT&gt; code, perhaps try the first one initially to see if there are any issues, then, if OK, the rest can be submitted in one go.&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;&lt;SPAN&gt;I hope that is clearer.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Please ask if you have any questions.&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;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Amir.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 13:18:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-multiple-files-to-Stata/m-p/555599#M9701</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2019-05-02T13:18:55Z</dc:date>
    </item>
    <item>
      <title>Re: Converting multiple files to Stata</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-multiple-files-to-Stata/m-p/555612#M9704</link>
      <description>Amazing, it worked!&lt;BR /&gt;Thanks a lot!</description>
      <pubDate>Thu, 02 May 2019 13:42:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-multiple-files-to-Stata/m-p/555612#M9704</guid>
      <dc:creator>alexia20</dc:creator>
      <dc:date>2019-05-02T13:42:59Z</dc:date>
    </item>
  </channel>
</rss>

