<?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 Executable procedure to convert SAS dataset to CSV in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Executable-procedure-to-convert-SAS-dataset-to-CSV/m-p/555625#M154636</link>
    <description>&lt;P&gt;I regularly have a requirement to convert files that I receive in sas7bdat format to csv. Currently, what I do is a very manual and idividualized&amp;nbsp;process where I need to log into the SAS Enterprise Guide, change the filenames in the procedure, and run the procedure for each file that needs to be converted. Is there any way to set up the program where it would run automatically (or with a variabe input) that could be called from some sort ofexecutable/script?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was thinking one of two possible solutions might work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;When the procedure is run, it scans $location for SAS datasets, and converts them to csv files.&lt;/LI&gt;&lt;LI&gt;The procedure gets a variable of $fileName fed to it (maybe when it gets called through a powershell/linux script), and proceeds to convert that file.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Is something like that feasible? My main goals are to limit the steps I need to&amp;nbsp;go through&amp;nbsp;when converting the files, as well as possibly making this process automatic/self-service where I wouldn't need to manually covert the files each time I receive a request.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For reference, the code that I currently use is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;libname aa '\\path\wher\file\is\located';

 

proc export data=aa.file

outfile='\\path\wher\file\is\located\file.csv'

dbms=csv 

replace;

putnames=yes;

run;&lt;/PRE&gt;&lt;P&gt;Thanks in advance! I am new to SAS, so I hope what I'm writing makes sense. If there's anything I could clarify, please let me know.&lt;/P&gt;</description>
    <pubDate>Thu, 02 May 2019 14:55:21 GMT</pubDate>
    <dc:creator>Salmononius2</dc:creator>
    <dc:date>2019-05-02T14:55:21Z</dc:date>
    <item>
      <title>Executable procedure to convert SAS dataset to CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Executable-procedure-to-convert-SAS-dataset-to-CSV/m-p/555625#M154636</link>
      <description>&lt;P&gt;I regularly have a requirement to convert files that I receive in sas7bdat format to csv. Currently, what I do is a very manual and idividualized&amp;nbsp;process where I need to log into the SAS Enterprise Guide, change the filenames in the procedure, and run the procedure for each file that needs to be converted. Is there any way to set up the program where it would run automatically (or with a variabe input) that could be called from some sort ofexecutable/script?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was thinking one of two possible solutions might work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;When the procedure is run, it scans $location for SAS datasets, and converts them to csv files.&lt;/LI&gt;&lt;LI&gt;The procedure gets a variable of $fileName fed to it (maybe when it gets called through a powershell/linux script), and proceeds to convert that file.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Is something like that feasible? My main goals are to limit the steps I need to&amp;nbsp;go through&amp;nbsp;when converting the files, as well as possibly making this process automatic/self-service where I wouldn't need to manually covert the files each time I receive a request.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For reference, the code that I currently use is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;libname aa '\\path\wher\file\is\located';

 

proc export data=aa.file

outfile='\\path\wher\file\is\located\file.csv'

dbms=csv 

replace;

putnames=yes;

run;&lt;/PRE&gt;&lt;P&gt;Thanks in advance! I am new to SAS, so I hope what I'm writing makes sense. If there's anything I could clarify, please let me know.&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 14:55:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Executable-procedure-to-convert-SAS-dataset-to-CSV/m-p/555625#M154636</guid>
      <dc:creator>Salmononius2</dc:creator>
      <dc:date>2019-05-02T14:55:21Z</dc:date>
    </item>
    <item>
      <title>Re: Executable procedure to convert SAS dataset to CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Executable-procedure-to-convert-SAS-dataset-to-CSV/m-p/555844#M154744</link>
      <description>&lt;P&gt;Welcome to the SAS forum!&lt;/P&gt;
&lt;P&gt;Both of these options are feasible.&lt;/P&gt;
&lt;P&gt;There is plenty of help already available here about scanning a directory and getting the file names.&lt;/P&gt;
&lt;P&gt;One of the simplest solution would be to:&lt;/P&gt;
&lt;P&gt;1. Have a data step scan the folder for file names.&lt;/P&gt;
&lt;P&gt;2. The same data step trigger proc import using the file name, via call execute.&lt;/P&gt;
&lt;P&gt;You should be able to find many examples of that kind of code for both these tasks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 05:41:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Executable-procedure-to-convert-SAS-dataset-to-CSV/m-p/555844#M154744</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-05-03T05:41:23Z</dc:date>
    </item>
    <item>
      <title>Re: Executable procedure to convert SAS dataset to CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Executable-procedure-to-convert-SAS-dataset-to-CSV/m-p/555855#M154751</link>
      <description>&lt;P&gt;Look here:&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/scottbass/SAS/tree/master/Macro" target="_blank" rel="noopener"&gt;https://github.com/scottbass/SAS/tree/master/Macro&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;esp:&lt;/P&gt;&lt;P&gt;dirlist&lt;/P&gt;&lt;P&gt;export&lt;/P&gt;&lt;P&gt;loop&lt;/P&gt;&lt;P&gt;loop_control&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Edit&lt;/STRONG&gt;:&amp;nbsp; So I read your post more closely.&amp;nbsp; This should get you started:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* create list of SAS datasets (adjust to suit) ;
proc sql;
   create table datasets as
   select catx('.',libname,memname) as dataset_name
   from dictionary.tables
   where libname='SASHELP'
     and memname in ('CLASS','CARS','DEMOGRAPHICS','SHOES','STOCKS')
   ;
quit;

* create space delimited list 
* this could have been done in one step above ;
proc sql noprint;
   select dataset_name into :datasets separated by " "
   from datasets;
run;

%put &amp;amp;=datasets;

* create macro to export to csv ;
* either proc export or my %export macro should work ;
%macro code;
   %let filename=%scan(&amp;amp;word,2,.);
   %let root=C:\Temp;
   %export(data=&amp;amp;word, file="&amp;amp;root\&amp;amp;filename..csv")
%mend;

* loop over the list of datasets ;
%loop(&amp;amp;datasets)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 May 2019 07:25:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Executable-procedure-to-convert-SAS-dataset-to-CSV/m-p/555855#M154751</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-05-03T07:25:18Z</dc:date>
    </item>
    <item>
      <title>Re: Executable procedure to convert SAS dataset to CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Executable-procedure-to-convert-SAS-dataset-to-CSV/m-p/556423#M155006</link>
      <description>&lt;P&gt;Thank you ChrisNZ and ScottBass! I think I'm good now with the first part, where I can loop through a directory and create a csv from each file in it (your comments helped me clarify what I needed to look for, and I was able to find this link: &lt;A href="https://communities.sas.com/t5/SAS-Programming/Export-multiple-tables-from-SAS-to-csv/td-p/27090" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Export-multiple-tables-from-SAS-to-csv/td-p/27090&lt;/A&gt;).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I'm up to the second part: Triggering the procedure from outside the SAS environment. I'm searching to see if there's anything on here already that could help (this link seems promising: &lt;A href="https://communities.sas.com/t5/General-SAS-Programming/Users-run-Sas-program-from-CMd-line/td-p/170957" target="_blank"&gt;https://communities.sas.com/t5/General-SAS-Programming/Users-run-Sas-program-from-CMd-line/td-p/170957&lt;/A&gt;). If anyone has any other suggestions, I would appreciate any ideas.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again for everyone's help!&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2019 14:08:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Executable-procedure-to-convert-SAS-dataset-to-CSV/m-p/556423#M155006</guid>
      <dc:creator>Salmononius2</dc:creator>
      <dc:date>2019-05-06T14:08:59Z</dc:date>
    </item>
    <item>
      <title>Re: Executable procedure to convert SAS dataset to CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Executable-procedure-to-convert-SAS-dataset-to-CSV/m-p/556613#M155061</link>
      <description>&lt;P&gt;You are on the right track. Look here too:&amp;nbsp;&lt;A href="http://support.sas.com/kb/25/213.html" target="_self"&gt;http://support.sas.com/kb/25/213.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2019 23:05:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Executable-procedure-to-convert-SAS-dataset-to-CSV/m-p/556613#M155061</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-05-06T23:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: Executable procedure to convert SAS dataset to CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Executable-procedure-to-convert-SAS-dataset-to-CSV/m-p/556629#M155067</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/272629"&gt;@Salmononius2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;I think I'm good now with the first part, where I can loop through a directory and create a csv from each file in it&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I recommend getting the list of SAS datasets from within SAS, rather than looping through a physical directory.&amp;nbsp; For example, your approach would not work if you were using the SPDE engine.&amp;nbsp; Instead, use the SAS dictionary tables to get your list of SAS tables.&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 02:07:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Executable-procedure-to-convert-SAS-dataset-to-CSV/m-p/556629#M155067</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-05-07T02:07:22Z</dc:date>
    </item>
    <item>
      <title>Re: Executable procedure to convert SAS dataset to CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Executable-procedure-to-convert-SAS-dataset-to-CSV/m-p/556665#M155092</link>
      <description>&lt;P&gt;There are two parts to your question. To enhance your code to convert ALL of the datasets you just need to use the list of dataset to drive generating the conversion code.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path=\\path\wher\file\is\located;

libname aa "&amp;amp;path" access=readonly;
proc contents data=aa._all_ noprint out=contents; run;
data _null_;
  set contents ;
  by memname ;
  if first.memname;
  call execute(catx(' '
,'proc export data=',catx('.',libname,memname)
,cats('outfile="&amp;amp;path/',memname,'.csv"'
,'dbms=csv replace;'
,'putnames=yes;'
,'run;'
 ));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When you use Enterprise Guide where is the SAS server that you are connecting to?&lt;/P&gt;
&lt;P&gt;Can you run SAS on that server without using Enterprise Guide?&lt;/P&gt;
&lt;P&gt;If so then you can create a program with the code above and then at the command prompt just use the command sas to run the program.&amp;nbsp; Now you might want to modify the program to allow you to pass in the path to the files to convert.&amp;nbsp; Note this would be much easier on Windows if the path was mapped to a drive letter. Then you could hard code the program to just use the current directory by just changing the %LET statement to :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path=.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So then to convert all of the files in a directory you would just run these two commands:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;cd \path\to\files
sas \path\to\program&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 May 2019 05:13:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Executable-procedure-to-convert-SAS-dataset-to-CSV/m-p/556665#M155092</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-07T05:13:22Z</dc:date>
    </item>
    <item>
      <title>Re: Executable procedure to convert SAS dataset to CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Executable-procedure-to-convert-SAS-dataset-to-CSV/m-p/556722#M155111</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro csvOut(dataset, path, outname);

	%if &amp;amp;amp;OUTNAME EQ %THEN %let outname = &amp;amp;amp;dataset ;

		proc export
		data = &amp;amp;amp;dataset
		outfile=&amp;amp;quot;&amp;amp;amp;path./&amp;amp;amp;outname..csv&amp;amp;quot;
		dbms=csv
		replace;
		run;

%mend;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is my macro for export csv, I don't know if you can use it !&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 10:22:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Executable-procedure-to-convert-SAS-dataset-to-CSV/m-p/556722#M155111</guid>
      <dc:creator>Onizuka</dc:creator>
      <dc:date>2019-05-07T10:22:42Z</dc:date>
    </item>
  </channel>
</rss>

