<?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 How to export library of SAS files as .csv files? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-export-library-of-SAS-files-as-csv-files/m-p/686215#M24400</link>
    <description>&lt;P&gt;I have a folder of SAS data files. My goal is to take each of those files and convert it into a csv file. I want all those csv files to be in their own folder. Thus, I will have one folder of the initial SAS files, as well as one folder of the respective csv files.&lt;/P&gt;&lt;P&gt;I know how to convert individual SAS files to csv, but I'm not sure how to do it across an entire library.&lt;/P&gt;&lt;P&gt;Also, I need the csv files to have the same name as the respective SAS files, except with a .csv at the end, obviously.&lt;/P&gt;</description>
    <pubDate>Wed, 23 Sep 2020 21:05:11 GMT</pubDate>
    <dc:creator>AbOnTheCob</dc:creator>
    <dc:date>2020-09-23T21:05:11Z</dc:date>
    <item>
      <title>How to export library of SAS files as .csv files?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-export-library-of-SAS-files-as-csv-files/m-p/686215#M24400</link>
      <description>&lt;P&gt;I have a folder of SAS data files. My goal is to take each of those files and convert it into a csv file. I want all those csv files to be in their own folder. Thus, I will have one folder of the initial SAS files, as well as one folder of the respective csv files.&lt;/P&gt;&lt;P&gt;I know how to convert individual SAS files to csv, but I'm not sure how to do it across an entire library.&lt;/P&gt;&lt;P&gt;Also, I need the csv files to have the same name as the respective SAS files, except with a .csv at the end, obviously.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 21:05:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-export-library-of-SAS-files-as-csv-files/m-p/686215#M24400</guid>
      <dc:creator>AbOnTheCob</dc:creator>
      <dc:date>2020-09-23T21:05:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to export library of SAS files as .csv files?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-export-library-of-SAS-files-as-csv-files/m-p/686236#M24403</link>
      <description>&lt;P&gt;Retrieve the dataset names for a library from SASHELP.VTABLE in a DATA _NULL_&amp;nbsp; step, and use CALL EXECUTE to create the PROC EXPORT code for each.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 22:16:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-export-library-of-SAS-files-as-csv-files/m-p/686236#M24403</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-23T22:16:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to export library of SAS files as .csv files?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-export-library-of-SAS-files-as-csv-files/m-p/686500#M24437</link>
      <description>&lt;P&gt;Hi, thanks for the response. Sorry to bother but could you elaborate on how to retrieve the dataset names from sashelp.vtable? I understand I need to do&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set sashelp.vtable;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but I'm not sure where to go from there. Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2020 19:47:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-export-library-of-SAS-files-as-csv-files/m-p/686500#M24437</guid>
      <dc:creator>AbOnTheCob</dc:creator>
      <dc:date>2020-09-24T19:47:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to export library of SAS files as .csv files?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-export-library-of-SAS-files-as-csv-files/m-p/686510#M24438</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set sashelp.vtable;
where libname = "YOUR_LIB"; /* all uppercase! */
call execute("
  proc export
    data=YOUR_LIB." !! strip(memname) !! "
    outfile='path_to_your_files/" !! lowcase(strip(memname)) !! ".csv'
    dbms=csv
    replace
  ;
  run;
");
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, posted from my tablet.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2020 20:17:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-export-library-of-SAS-files-as-csv-files/m-p/686510#M24438</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-24T20:17:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to export library of SAS files as .csv files?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-export-library-of-SAS-files-as-csv-files/m-p/686800#M24475</link>
      <description>&lt;P&gt;Here's a full solution.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Change the library at the top of the program and the path to where you want the files to be saved and it will dynamically create the folders and files for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options dlcreatedir;

proc options option=dlcreatedir;
run;

*SET THESE TO BE FOR YOUR CODE;
%let lib2export = WORK;
%let path2files = /home/demo/;


*DO NOT CHANGE BELOW;


data _null_;
*list of files;
set sashelp.vtable(where = (libname = "&amp;amp;lib2export") keep = libname memname);

*create folder path for files to be stored;
folder4file = catt("&amp;amp;path2files.", memname);

*use libname to create folders;
rc_open = libname('demo1', folder4file) ;
rc_close = libname('demo1');

file2export = catt(folder4file, "/", memname, ".csv");

*export file;
length str $300.;
str = catt("proc export data=", 
			"&amp;amp;lib2export.", 
			".",
			memname, 
			" outfile=",
			trim(quote(file2export)),
			" dbms=csv replace;run;");
			
call execute (str);

run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to understand the code, I would suggest saving it to a data set and then examining the data set.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;

*becomes;

data exportFiles;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you need to debug it, comment out the CALL EXECUTE line and make sure the code generated in STR is correct.&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/348852"&gt;@AbOnTheCob&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a folder of SAS data files. My goal is to take each of those files and convert it into a csv file. I want all those csv files to be in their own folder. Thus, I will have one folder of the initial SAS files, as well as one folder of the respective csv files.&lt;/P&gt;
&lt;P&gt;I know how to convert individual SAS files to csv, but I'm not sure how to do it across an entire library.&lt;/P&gt;
&lt;P&gt;Also, I need the csv files to have the same name as the respective SAS files, except with a .csv at the end, obviously.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2020 18:23:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-export-library-of-SAS-files-as-csv-files/m-p/686800#M24475</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-09-25T18:23:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to export library of SAS files as .csv files?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-export-library-of-SAS-files-as-csv-files/m-p/884858#M39277</link>
      <description>Thank you, Kurt. This worked perfectly (as compared to all the other posted methods online which did not work at all for me).</description>
      <pubDate>Fri, 14 Jul 2023 18:43:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-export-library-of-SAS-files-as-csv-files/m-p/884858#M39277</guid>
      <dc:creator>SmasherDA</dc:creator>
      <dc:date>2023-07-14T18:43:57Z</dc:date>
    </item>
  </channel>
</rss>

