<?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: Determining automatic file names in proc export in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Determining-automatic-file-names-in-proc-export/m-p/284081#M59293</link>
    <description>&lt;P&gt;Wouldn't the file created in Step be the latest one? You can't use that same path?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise you need to work backwards. Assign a libname to where the files are stored, get all file names and parse out date/time to find the latest dataset.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can get the list of datasets from sashelp.vtable once the libname has been assigned.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Jul 2016 15:18:26 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-07-13T15:18:26Z</dc:date>
    <item>
      <title>Determining automatic file names in proc export</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Determining-automatic-file-names-in-proc-export/m-p/284046#M59286</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a program that I run daily and I save certain&amp;nbsp;&amp;nbsp;proc freq outputs into&amp;nbsp;datasets using &amp;amp;systime and &amp;amp;sysdate9 to generate the file names. What I would like to do now is export the newly created file into an excel sheet and replace the current sheet each time I run the program. I need a way to tell SAS to use the most recent dataset to export&amp;nbsp;in that specific library.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Essentailly I want the program to go like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Step 1: Run todays Freq&lt;/P&gt;&lt;P&gt;Step 2: Save it as a data file &amp;nbsp;&lt;/P&gt;&lt;P&gt;Step 3: Export it into a sheet and replace the current sheet.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I need help with is how to tell proc export which filename to use automatically.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code that I have:&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;proc freq data=assessedkids3;
tables CaseDispositionDesc/ out=caseDispositionDaily sparse ; /*makes a dataset named caseDispositionDaily*/
title "Daily Case Disposition &amp;amp;sysdate ";/*&amp;amp;sysdate to produce date*/
run;
/*Step 3*/
data _null_;
cdate = "&amp;amp;SYSDATE9";
ctime = "&amp;amp;SYSTIME";
time_string = cdate||"_"||translate(ctime, "_", ":");
call symput('hw_time', time_string); /*name the variable between ''*/
run;
/*Step 4*/
data "C:\Case_Disposition_Dailyrun\casedis_daily\casedisposition_&amp;amp;hw_time";
set caseDispositionDaily;
run;

PROC EXPORT DATA = &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;Automatically select file here&lt;/STRONG&gt;&lt;/FONT&gt;
OUTFILE = "C:\dashboard.xlsx"
DBMS=xlsx REPLACE;
Sheet = "Data";
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Any advice would be greatly appreciated!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2016 14:33:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Determining-automatic-file-names-in-proc-export/m-p/284046#M59286</guid>
      <dc:creator>hwangnyc</dc:creator>
      <dc:date>2016-07-13T14:33:12Z</dc:date>
    </item>
    <item>
      <title>Re: Determining automatic file names in proc export</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Determining-automatic-file-names-in-proc-export/m-p/284059#M59287</link>
      <description>&lt;P&gt;Isn't it the same as what you have for step 4 in your data statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is is there a reason your referring to the full file path rather than assigning a libname!&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2016 14:55:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Determining-automatic-file-names-in-proc-export/m-p/284059#M59287</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-07-13T14:55:51Z</dc:date>
    </item>
    <item>
      <title>Re: Determining automatic file names in proc export</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Determining-automatic-file-names-in-proc-export/m-p/284066#M59288</link>
      <description>&lt;P&gt;Hi Reeza,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the response. I'm not sure what you mean regarding both statements. I'm sure my code is inefficient, could you elorbrate as to where I can improve?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2016 15:02:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Determining-automatic-file-names-in-proc-export/m-p/284066#M59288</guid>
      <dc:creator>hwangnyc</dc:creator>
      <dc:date>2016-07-13T15:02:51Z</dc:date>
    </item>
    <item>
      <title>Re: Determining automatic file names in proc export</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Determining-automatic-file-names-in-proc-export/m-p/284072#M59290</link>
      <description>&lt;P&gt;Step 4. That dataset being created is the one you want to export?&lt;/P&gt;
&lt;P&gt;If so, the way you reference it when creating it is the same as how you reference it to export it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Typically you see:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data libname.datasetname;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOT file paths. You can do that, it's just not very common.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2016 15:07:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Determining-automatic-file-names-in-proc-export/m-p/284072#M59290</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-07-13T15:07:42Z</dc:date>
    </item>
    <item>
      <title>Re: Determining automatic file names in proc export</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Determining-automatic-file-names-in-proc-export/m-p/284079#M59292</link>
      <description>&lt;P&gt;Right, gotcha. So in step 4 the program&amp;nbsp;uses a file path because it is assigning a date and time to the file name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I get Proc Export to pick up the most recently created file?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Step 3*/
data _null_;
  cdate2 =  "&amp;amp;SYSDATE9";
  ctime2 = "&amp;amp;SYSTIME";
  time_string = cdate2||"_"||translate(ctime2, "_", ":");
  call symput('hw_time2', time_string); /*name the variable between ''*/
run;
/*Step 4*/
data "S:\CommunityHealth\DPHO-Harlem\Research, Evaluation, and Planning\Henry\EHACE\Case_Disposition_Dailyrun\counselor_daily\casedis_Coun_&amp;amp;hw_time2";
  set caseDisposition_counselorDaily;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Jul 2016 15:13:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Determining-automatic-file-names-in-proc-export/m-p/284079#M59292</guid>
      <dc:creator>hwangnyc</dc:creator>
      <dc:date>2016-07-13T15:13:57Z</dc:date>
    </item>
    <item>
      <title>Re: Determining automatic file names in proc export</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Determining-automatic-file-names-in-proc-export/m-p/284081#M59293</link>
      <description>&lt;P&gt;Wouldn't the file created in Step be the latest one? You can't use that same path?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise you need to work backwards. Assign a libname to where the files are stored, get all file names and parse out date/time to find the latest dataset.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can get the list of datasets from sashelp.vtable once the libname has been assigned.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2016 15:18:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Determining-automatic-file-names-in-proc-export/m-p/284081#M59293</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-07-13T15:18:26Z</dc:date>
    </item>
    <item>
      <title>Re: Determining automatic file names in proc export</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Determining-automatic-file-names-in-proc-export/m-p/284084#M59294</link>
      <description>&lt;P&gt;Use the automatic macro variable SYSLAST.&lt;/P&gt;
&lt;P&gt;If I run this code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data "&amp;amp;path\fred.sas7bdat";
 set sashelp.class;
run;

%let mydsn=&amp;amp;syslast;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then the macro variable MYDSN will have the value&amp;nbsp;WC000002.FRED. &amp;nbsp;Note that the libref that SAS automatically created because I used the physical path of the file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2016 15:24:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Determining-automatic-file-names-in-proc-export/m-p/284084#M59294</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-07-13T15:24:57Z</dc:date>
    </item>
    <item>
      <title>Re: Determining automatic file names in proc export</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Determining-automatic-file-names-in-proc-export/m-p/284085#M59295</link>
      <description>&lt;P&gt;I ended up creating a libname pointing to the path then used the the same file name as it was listed in step 4. It worked like a charm! I imagine though, since my filename has a time componenet it would only work if the program was all run together. As in if I run it at a later time the filename would be different. Does that make sense?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2016 15:28:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Determining-automatic-file-names-in-proc-export/m-p/284085#M59295</guid>
      <dc:creator>hwangnyc</dc:creator>
      <dc:date>2016-07-13T15:28:24Z</dc:date>
    </item>
  </channel>
</rss>

