<?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: File name automation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56498#M12079</link>
    <description>Hello.&lt;BR /&gt;
&lt;BR /&gt;
OK. I couldn't get your renaming piece of code to work properly at my workstation (maybe something missing that was crunched from the post?), so in order to test the complete solution, I ended up redesigning the file renaming piece (same thing, another approach) and adjusting the tab renaming macro.&lt;BR /&gt;
&lt;BR /&gt;
I have also introduced some artificial delays (1 second each, and adjustable), because I suspect that there is maybe a lag introduced by excel's launch or/and the issued rename command.&lt;BR /&gt;
&lt;BR /&gt;
This code was tested and is working on my SAS 9.1.3 SP4/MS Excel 2003 (WinXP 32b) workstation configuration.&lt;BR /&gt;
&lt;BR /&gt;
Just need to adjust the macro variables MY_DIR, SOURCE and TARGET to suit your needs (see code bellow).&lt;BR /&gt;
&lt;BR /&gt;
PLEASE verify that the path of MS Excel is correct and that your regional settings specify the ; char as the list separator. If not, please do the necessary modifications (see comments) on the code bellow:&lt;BR /&gt;
&lt;BR /&gt;
options noxsync noxwait xmin; * assynchronous execution;&lt;BR /&gt;
&lt;BR /&gt;
/************************************************************************/&lt;BR /&gt;
&lt;BR /&gt;
* macro for excel worksheet renaming;&lt;BR /&gt;
%macro ren_sheettab(DIRNAME,FILENAME);&lt;BR /&gt;
&lt;BR /&gt;
* DIRNAME = directory name of the excel file (no tailing \);&lt;BR /&gt;
* FILENAME = filename of the excel (no .extension);&lt;BR /&gt;
&lt;BR /&gt;
* alocates connection do DDE server;&lt;BR /&gt;
filename xlfile dde 'excel|system'; * assumes DDE server is running;&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
file xlfile; * inits DDE connection;&lt;BR /&gt;
put "[OPEN(""&amp;amp;DIRNAME\&amp;amp;FILENAME..xls"")]"; * opens desired workbook;&lt;BR /&gt;
put '[WORKBOOK.NEXT()]'; * activates the next worksheet;&lt;BR /&gt;
put '[WORKBOOK.INSERT(3)]'; * insert new macro worksheet;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
* prepare macro for worksheet renaming;&lt;BR /&gt;
filename xlmacro dde 'excel|Macro1!r1c1:r2c1' notab; &lt;BR /&gt;
data _null_;&lt;BR /&gt;
file xlmacro;&lt;BR /&gt;
* write macro code;&lt;BR /&gt;
/***** adjust the char list separator if necessary!!! *****/&lt;BR /&gt;
put "=WORKBOOK.NAME(""Sheet1"";""&amp;amp;FILENAME"")"; * uses name function;&lt;BR /&gt;
/***** adjust the char list separator if necessary!!! *****/&lt;BR /&gt;
put '=HALT(TRUE)'; * halts macro;&lt;BR /&gt;
put '!dde_flush'; * flushes DDE writte buffer;&lt;BR /&gt;
run;&lt;BR /&gt;
* run macro for tab renaming;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
file xlfile; * inits DDE connection;&lt;BR /&gt;
put '[RUN("Macro1!r1c1:r2c1")]'; * run macro;&lt;BR /&gt;
put '[ERROR(FALSE)]';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
* delete macro worksheet, save and quit;&lt;BR /&gt;
filename xlmacro clear;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
file xlfile;&lt;BR /&gt;
put '[WORKBOOK.ACTIVATE("Macro1")]'; * activate macro worksheet;&lt;BR /&gt;
put '[ERROR(FALSE)]';&lt;BR /&gt;
put '[WORKBOOK.DELETE()]'; * delete macro worksheet;&lt;BR /&gt;
put '[ERROR(TRUE)]';&lt;BR /&gt;
put '[SAVE()]'; * save workbook with renamed worksheet;&lt;BR /&gt;
put '[FILE.CLOSE(FALSE)]'; * close file;&lt;BR /&gt;
put '[QUIT()]'; * close DDE server;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%mend ren_sheettab;&lt;BR /&gt;
&lt;BR /&gt;
/************************************************************************/&lt;BR /&gt;
&lt;BR /&gt;
* 1. renames FIRST file matching *&amp;amp;SOURCE*.xls to &amp;amp;TARGET._YYYY_MM.xls;&lt;BR /&gt;
* 2. renames 'Sheet1' of the renamed file to to &amp;amp;TARGET._YYYY_MM;&lt;BR /&gt;
&lt;BR /&gt;
%let MY_DIR=D:\temp; * directory to scan;&lt;BR /&gt;
%let SOURCE=TESTE; * source text to search within filename;&lt;BR /&gt;
%let TARGET=XPTOX; * target text (prefix) to use for filename renaming;&lt;BR /&gt;
&lt;BR /&gt;
* start Excel DDE server;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
/***** adjust to your path if necessary!!! *****/&lt;BR /&gt;
x '"C:\Program Files\Microsoft Office\OFFICE11\excel.exe"';&lt;BR /&gt;
/***** adjust to your path if necessary!!! *****/&lt;BR /&gt;
call sleep(1,1); * custom delay of 1 second;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
* scan directory, search for mathcing filename, rename file, rename tab.;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
* associate directory;&lt;BR /&gt;
if not filename('MY_DIR',"&amp;amp;MY_DIR") then do;&lt;BR /&gt;
   D_ID=dopen('MY_DIR'); * open directory;&lt;BR /&gt;
   if not D_ID then stop;&lt;BR /&gt;
   M_IDX=1; * init directory member index;&lt;BR /&gt;
   do until (M_IDX gt dnum(D_ID)); * until there are no members;&lt;BR /&gt;
      NAME=dread(D_ID,M_IDX); * get member name;&lt;BR /&gt;
      F_ID=mopen(D_ID,NAME); * try to open member;&lt;BR /&gt;
      RC=fclose(F_ID); * close member;&lt;BR /&gt;
      * if it is a file and extension is .xls and source matches the name;&lt;BR /&gt;
      if F_ID and&lt;BR /&gt;
         upcase(substrn(strip(reverse(NAME)),1,4)) eq 'SLX.' and&lt;BR /&gt;
         index(upcase(NAME),upcase("&amp;amp;SOURCE")) then do;&lt;BR /&gt;
         * rename file;&lt;BR /&gt;
         TARGET=catx('_',"&amp;amp;TARGET",put(year(today()),z4.),put(month(today()),z2.));&lt;BR /&gt;
         call system("ren &amp;amp;MY_DIR\"!!strip(NAME)!!' '!!strip(TARGET)!!'.xls');&lt;BR /&gt;
         * rename tab;&lt;BR /&gt;
         call sleep(1,1); * custom delay of 1 second;&lt;BR /&gt;
         call execute('%ren_sheettab('!!strip("&amp;amp;MY_DIR")!!','!!strip(TARGET)!!');');&lt;BR /&gt;
		 RC=dclose(D_ID); * close directory;&lt;BR /&gt;
		 stop; * stop dataset execution;&lt;BR /&gt;
      end;   &lt;BR /&gt;
      M_IDX+1; * update index to next directory member;&lt;BR /&gt;
   end;&lt;BR /&gt;
   RC=dclose(D_ID); * close directory;&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
It may look very complex, but actually it is not. Almost every line is commented to help understanding.&lt;BR /&gt;
&lt;BR /&gt;
I'll post here some documentation after you get this to work.&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;.</description>
    <pubDate>Tue, 28 Jul 2009 14:46:17 GMT</pubDate>
    <dc:creator>DanielSantos</dc:creator>
    <dc:date>2009-07-28T14:46:17Z</dc:date>
    <item>
      <title>File name automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56472#M12053</link>
      <description>The excel file names that we recieve every month  are not consistent.This forces me to manually change the file name and then process them in SAS.&lt;BR /&gt;
Is there a way to change the file name programatically?&lt;BR /&gt;
Say for example , If the file contains "AETNA" , the file name is changed to AETNA_06_2009 for the current month and also the tab is changed  the same as file name, hence  the SAS dataset name is same as the tab.&lt;BR /&gt;
Thanks for the help in advance.</description>
      <pubDate>Fri, 17 Jul 2009 17:26:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56472#M12053</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2009-07-17T17:26:45Z</dc:date>
    </item>
    <item>
      <title>Re: File name automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56473#M12054</link>
      <description>data steps or macros are the usual choice for deriving things like this. Should be able to find examples in online doc as well as among Samples in &lt;A href="http://support.sas.com" target="_blank"&gt;http://support.sas.com&lt;/A&gt;.&lt;BR /&gt;
 &lt;BR /&gt;
good luck&lt;BR /&gt;
PeterC</description>
      <pubDate>Sun, 19 Jul 2009 09:59:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56473#M12054</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2009-07-19T09:59:20Z</dc:date>
    </item>
    <item>
      <title>Re: File name automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56474#M12055</link>
      <description>For this objective, the use of SAS functions like INTNX, SYMPUT (using CALL from a DATA step), and possibly the special-purpose %SYSFUNC (macro language call - permits you to integrate DATA step function calls) come to mind with either / both SAS DATA step and MACRO programming techniques.  &lt;BR /&gt;
&lt;BR /&gt;
As mentioned in this thread, the SAS support website can offer both SAS-hosted documentation but more importantly the supplemental technical / conference papers on this type of topic -- explore the site using the SEARCH facility for code automation (topic: using SAS code to generate SAS code) examples.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Sun, 19 Jul 2009 15:31:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56474#M12055</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-07-19T15:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: File name automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56475#M12056</link>
      <description>Hi SASPhile &lt;BR /&gt;
&lt;BR /&gt;
This simple code will help you &lt;BR /&gt;
&lt;BR /&gt;
%let my_dir=e:\my_excel_files;&lt;BR /&gt;
filename dir pipe "dir &amp;amp;my_dir";&lt;BR /&gt;
&lt;BR /&gt;
data d;&lt;BR /&gt;
infile dir pad truncover;&lt;BR /&gt;
input date $10.@;&lt;BR /&gt;
if date ='' or date='Volume' or length(date) &amp;lt;10 then  delete;&lt;BR /&gt;
else input  time $ ampm $ dir $ name $20.;&lt;BR /&gt;
if trim(dir)='&lt;DIR&gt;' then delete;&lt;BR /&gt;
if index(name,'AETNA') then&lt;BR /&gt;
   do;&lt;BR /&gt;
    nm=scan(name ,1,'.'); &lt;BR /&gt;
    cmd="ren &amp;amp;my_dir\"||trim(left(name)) ||' '||compress(left(nm)||put(month(today()),z2.)||'_'||year(today())||'.xls') ;&lt;BR /&gt;
    put cmd=;&lt;BR /&gt;
    rc=system(cmd);&lt;BR /&gt;
   end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
lu&lt;/DIR&gt;</description>
      <pubDate>Mon, 20 Jul 2009 07:06:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56475#M12056</guid>
      <dc:creator>lu</dc:creator>
      <dc:date>2009-07-20T07:06:28Z</dc:date>
    </item>
    <item>
      <title>Re: File name automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56476#M12057</link>
      <description>I will add the following to lu's code for the tab renaming issue, (explanation bellow).&lt;BR /&gt;
&lt;BR /&gt;
Note1: assumes a &amp;amp;FILENAME macro has the renamed filename without extension (say=AETNA_06_2009).&lt;BR /&gt;
Note2: assumes that the original name of the worksheet to be renamed is "Sheet1".&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
options noxsync noxwait xmin; * assynchronous execution;&lt;BR /&gt;
&lt;BR /&gt;
* start Excel DDE server;&lt;BR /&gt;
x 'excel.exe'; /* you may need to add the full path */&lt;BR /&gt;
&lt;BR /&gt;
filename xlfile dde 'excel|system';&lt;BR /&gt;
data _null_;&lt;BR /&gt;
file xlfile; * start DDE connection and open desired workbook;&lt;BR /&gt;
put '[OPEN("&lt;DIR&gt;\&amp;amp;FILENAME..xls")]'; /* replace with your &lt;DIR&gt; */&lt;BR /&gt;
put '[WORKBOOK.NEXT()]';&lt;BR /&gt;
put '[WORKBOOK.INSERT(3)]'; * insert new macro worksheet;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
* prepare macro for worksheet renaming;&lt;BR /&gt;
filename xlmacro dde 'excel|Macro1!r1c1:r2c1' notab;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
file xlmacro;&lt;BR /&gt;
* write macro code;&lt;BR /&gt;
put '=WORKBOOK.NAME("Sheet1","&amp;amp;FILENAME")';&lt;BR /&gt;
put '=HALT(TRUE)';&lt;BR /&gt;
put '!dde_flush';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
* rename worksheet by running macro;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
file xlfile;&lt;BR /&gt;
put '[RUN("Macro1!r1c1")]';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
* delete macro worksheet;&lt;BR /&gt;
filename xlmacro clear;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
file xlfile;&lt;BR /&gt;
put '[WORKBOOK.ACTIVATE("Macro1")]';&lt;BR /&gt;
put '[ERROR(FALSE)]';&lt;BR /&gt;
put '[WORKBOOK.DELETE()]';&lt;BR /&gt;
put '[ERROR(TRUE)]';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
This is a known workaround for a knowned DDE problem (function WORKBOOK.NAME("old_name", "new_name") not working properly when evoked through the DDE engine). &lt;BR /&gt;
Trick is to create a new worksheet (Macro1) and write there the macro code for the worksheet renaming. Then execute it. Then delete it.&lt;BR /&gt;
&lt;BR /&gt;
Check Koen Vyverman's SAS paper about DDE:&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi27/p190-27.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi27/p190-27.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;.&lt;/DIR&gt;&lt;/DIR&gt;</description>
      <pubDate>Mon, 20 Jul 2009 10:55:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56476#M12057</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-07-20T10:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: File name automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56477#M12058</link>
      <description>Lu,&lt;BR /&gt;
does this change the name of the file physically?&lt;BR /&gt;
cmd="ren &amp;amp;my_dir\"||trim(left(name)) ||' '||compress(left(nm)||put(month(today()),z2.)||'_'||year(today())||'.xls') ;</description>
      <pubDate>Tue, 21 Jul 2009 20:26:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56477#M12058</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2009-07-21T20:26:04Z</dc:date>
    </item>
    <item>
      <title>Re: File name automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56478#M12059</link>
      <description>Hi,&lt;BR /&gt;
This is character string contain command 'rename...' .&lt;BR /&gt;
to run  command on OS - rc=system(cmd);.&lt;BR /&gt;
And this is change the name of the file physically&lt;BR /&gt;
&lt;BR /&gt;
lu</description>
      <pubDate>Wed, 22 Jul 2009 05:16:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56478#M12059</guid>
      <dc:creator>lu</dc:creator>
      <dc:date>2009-07-22T05:16:35Z</dc:date>
    </item>
    <item>
      <title>Re: File name automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56479#M12060</link>
      <description>I tried using this and did not change the name physically!</description>
      <pubDate>Wed, 22 Jul 2009 13:43:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56479#M12060</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2009-07-22T13:43:05Z</dc:date>
    </item>
    <item>
      <title>Re: File name automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56480#M12061</link>
      <description>Hi.&lt;BR /&gt;
&lt;BR /&gt;
Try this macro (if you work under Windows)&lt;BR /&gt;
&lt;BR /&gt;
  %macro rename(input=d:\work\test rename,m=06,y=2009);&lt;BR /&gt;
  %let dlm=\;&lt;BR /&gt;
  %let filrf=mydir;&lt;BR /&gt;
  %let rc=%sysfunc(filename(filrf,"&amp;amp;input"));&lt;BR /&gt;
  %let did=%sysfunc(dopen(&amp;amp;filrf));&lt;BR /&gt;
  %let lstname=;&lt;BR /&gt;
   %let memcount=%sysfunc(dnum(&amp;amp;did));&lt;BR /&gt;
  %if &amp;amp;memcount &amp;gt; 0 %then %do;&lt;BR /&gt;
  %do i=1 %to &amp;amp;memcount;&lt;BR /&gt;
  %let lstname=%sysfunc(dread(&amp;amp;did,&amp;amp;i));&lt;BR /&gt;
  %let file=&amp;amp;input&amp;amp;dlm&amp;amp;lstname;&lt;BR /&gt;
   %if %sysfunc(index(&amp;amp;lstname,AETNA)) ne 0&lt;BR /&gt;
   %then %do;&lt;BR /&gt;
   x move "&amp;amp;file" "&amp;amp;input&amp;amp;dlm.AETNA_&amp;amp;m._&amp;amp;y";&lt;BR /&gt;
   %end;&lt;BR /&gt;
  %end;&lt;BR /&gt;
  %let rc=%sysfunc(dclose(&amp;amp;did));&lt;BR /&gt;
  %end;&lt;BR /&gt;
  %mend rename;&lt;BR /&gt;
&lt;BR /&gt;
  options mprint symbolgen noxwait;&lt;BR /&gt;
  %rename;</description>
      <pubDate>Wed, 22 Jul 2009 14:10:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56480#M12061</guid>
      <dc:creator>Oleg_L</dc:creator>
      <dc:date>2009-07-22T14:10:06Z</dc:date>
    </item>
    <item>
      <title>Re: File name automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56481#M12062</link>
      <description>Sorry.&lt;BR /&gt;
I forgot upcase checking and xls extension for out:&lt;BR /&gt;
&lt;BR /&gt;
  %macro rename(input=d:\work\test rename,m=06,y=2009);&lt;BR /&gt;
  %let dlm=\;&lt;BR /&gt;
  %let filrf=mydir;&lt;BR /&gt;
  %let rc=%sysfunc(filename(filrf,"&amp;amp;input"));&lt;BR /&gt;
  %let did=%sysfunc(dopen(&amp;amp;filrf));&lt;BR /&gt;
  %let lstname=;&lt;BR /&gt;
   %let memcount=%sysfunc(dnum(&amp;amp;did));&lt;BR /&gt;
  %if &amp;amp;memcount &amp;gt; 0 %then %do;&lt;BR /&gt;
  %do i=1 %to &amp;amp;memcount;&lt;BR /&gt;
  %let lstname=%sysfunc(dread(&amp;amp;did,&amp;amp;i));&lt;BR /&gt;
  %let file=&amp;amp;input&amp;amp;dlm&amp;amp;lstname;&lt;BR /&gt;
   %if %sysfunc(index(%sysfunc(upcase(&amp;amp;lstname)),AETNA)) ne 0&lt;BR /&gt;
   %then %do;&lt;BR /&gt;
   x move "&amp;amp;file" "&amp;amp;input&amp;amp;dlm.AETNA_&amp;amp;m._&amp;amp;y..xls";&lt;BR /&gt;
   %end;&lt;BR /&gt;
  %end;&lt;BR /&gt;
  %let rc=%sysfunc(dclose(&amp;amp;did));&lt;BR /&gt;
  %end;&lt;BR /&gt;
  %mend rename;&lt;BR /&gt;
&lt;BR /&gt;
  options mprint symbolgen noxwait;&lt;BR /&gt;
  %rename;</description>
      <pubDate>Wed, 22 Jul 2009 14:42:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56481#M12062</guid>
      <dc:creator>Oleg_L</dc:creator>
      <dc:date>2009-07-22T14:42:50Z</dc:date>
    </item>
    <item>
      <title>Re: File name automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56482#M12063</link>
      <description>SASPhile,&lt;BR /&gt;
pls let me to know:&lt;BR /&gt;
1.do you use Windows or Unix/Linux OS?&lt;BR /&gt;
2.What do you see in LOG after statement    put cmd=;  ?&lt;BR /&gt;
3.chek in data set d variable RC = ???&lt;BR /&gt;
&lt;BR /&gt;
lu</description>
      <pubDate>Wed, 22 Jul 2009 17:59:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56482#M12063</guid>
      <dc:creator>lu</dc:creator>
      <dc:date>2009-07-22T17:59:26Z</dc:date>
    </item>
    <item>
      <title>Re: File name automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56483#M12064</link>
      <description>I use windows.&lt;BR /&gt;
This is the code I used.&lt;BR /&gt;
&lt;BR /&gt;
The input file present in my_dir is:&lt;BR /&gt;
2009 June GH Utilization - Unblinded.xls&lt;BR /&gt;
My objective is 2009 June GH Utilization  is present &lt;BR /&gt;
then chnage the file name to caremark_2009_07.xls&lt;BR /&gt;
and the tab to caremark_2009_07.&lt;BR /&gt;
&lt;BR /&gt;
 %let my_dir=C:\Documents and Settings\skap\Desktop\inpt;&lt;BR /&gt;
filename dir pipe "dir &amp;amp;my_dir";&lt;BR /&gt;
&lt;BR /&gt;
data d;&lt;BR /&gt;
infile dir pad truncover;&lt;BR /&gt;
input date $10.@;&lt;BR /&gt;
if date ='' or date='Volume' or length(date) &amp;lt;10 then delete;&lt;BR /&gt;
else input time $ ampm $ dir $ name $20.;&lt;BR /&gt;
if trim(dir)='&lt;DIR&gt;' then delete;&lt;BR /&gt;
if index(name,'GH Utilization') then&lt;BR /&gt;
do;&lt;BR /&gt;
nm=scan(name ,1,'.'); &lt;BR /&gt;
cmd="ren &amp;amp;my_dir\"||trim(left(name)) ||' '||compress(left(nm)||put(month(today()),z2.)||'_'||year(today())||'.xls') ;&lt;BR /&gt;
put cmd=;&lt;BR /&gt;
rc=system(cmd);&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
The log is:&lt;BR /&gt;
&lt;BR /&gt;
623   %let my_dir=C:\Documents and Settings\skap\Desktop\inpt;&lt;BR /&gt;
624  filename dir pipe "dir &amp;amp;my_dir";&lt;BR /&gt;
625&lt;BR /&gt;
626  data d;&lt;BR /&gt;
627  infile dir pad truncover;&lt;BR /&gt;
628  input date $10.@;&lt;BR /&gt;
629  if date ='' or date='Volume' or length(date) &amp;lt;10 then delete;&lt;BR /&gt;
630  else input time $ ampm $ dir $ name $20.;&lt;BR /&gt;
631  if trim(dir)='&lt;DIR&gt;' then delete;&lt;BR /&gt;
632  if index(name,'GH Utilization') then&lt;BR /&gt;
633  do;&lt;BR /&gt;
634  nm=scan(name ,1,'.');&lt;BR /&gt;
635  cmd="ren &amp;amp;my_dir\"||trim(left(name)) ||'&lt;BR /&gt;
635! '||compress(left(nm)||put(month(today()),z2.)||'_'||year(today())||'.xls') ;&lt;BR /&gt;
636  put cmd=;&lt;BR /&gt;
637  rc=system(cmd);&lt;BR /&gt;
638  end;&lt;BR /&gt;
639  run;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: Numeric values have been converted to character values at the places given by:&lt;BR /&gt;
      (Line):(Column).&lt;BR /&gt;
      635:94&lt;BR /&gt;
NOTE: The infile DIR is:&lt;BR /&gt;
      Unnamed Pipe Access Device,&lt;BR /&gt;
      PROCESS=dir C:\Documents and Settings\skap\Desktop\inpt,&lt;BR /&gt;
      RECFM=V,LRECL=256&lt;BR /&gt;
&lt;BR /&gt;
Stderr output:&lt;BR /&gt;
The system cannot find the path specified.&lt;BR /&gt;
NOTE: 0 records were read from the infile DIR.&lt;BR /&gt;
NOTE: The data set WORK.D has 0 observations and 8 variables.&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.10 seconds&lt;BR /&gt;
      cpu time            0.01 seconds&lt;/DIR&gt;&lt;/DIR&gt;</description>
      <pubDate>Wed, 22 Jul 2009 18:12:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56483#M12064</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2009-07-22T18:12:37Z</dc:date>
    </item>
    <item>
      <title>Re: File name automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56484#M12065</link>
      <description>ok ,&lt;BR /&gt;
the problem is blanks in path - C:\Documents and Settings\skap\Desktop\inpt;&lt;BR /&gt;
try something without blank -  c:\inpt; . If you must this path  I will fix it tomorrow&lt;BR /&gt;
I haven't access to SAS Windows  now .&lt;BR /&gt;
&lt;BR /&gt;
lu</description>
      <pubDate>Wed, 22 Jul 2009 18:41:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56484#M12065</guid>
      <dc:creator>lu</dc:creator>
      <dc:date>2009-07-22T18:41:31Z</dc:date>
    </item>
    <item>
      <title>Re: File name automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56485#M12066</link>
      <description>thank you !</description>
      <pubDate>Wed, 22 Jul 2009 19:10:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56485#M12066</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2009-07-22T19:10:42Z</dc:date>
    </item>
    <item>
      <title>Re: File name automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56486#M12067</link>
      <description>Hi ,SASPhile, Fixed code: &lt;BR /&gt;
options noxwait;&lt;BR /&gt;
%let my_dir=C:\Documents and Settings\skap\Desktop\inpt;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
 dir_cmd='dir "'||"&amp;amp;my_dir"||'"';&lt;BR /&gt;
 rc=filename('dir',dir_cmd,'pipe');&lt;BR /&gt;
 run;&lt;BR /&gt;
data d;&lt;BR /&gt;
infile dir pad truncover;&lt;BR /&gt;
input date $10.@;&lt;BR /&gt;
if date ='' or date='Volume' or length(date) &amp;lt;10 then  delete;&lt;BR /&gt;
else input  time $ ampm $ dir $ name $200.;&lt;BR /&gt;
if trim(dir)='&lt;DIR&gt;' then delete;&lt;BR /&gt;
if index(name,'GH Utilization') then&lt;BR /&gt;
   do;&lt;BR /&gt;
    nm='caremark'; &lt;BR /&gt;
    cmd='ren "'||"&amp;amp;my_dir\"||trim(left(name)) ||'" "'||compress(left(nm)||'_'||year(today())||'_'||put(month(today()),z2.)||'.xls"') ;&lt;BR /&gt;
    put cmd=;&lt;BR /&gt;
    rc=system(cmd);&lt;BR /&gt;
   end;&lt;BR /&gt;
run;&lt;BR /&gt;
lu.

Message was edited by: lu&lt;/DIR&gt;</description>
      <pubDate>Thu, 23 Jul 2009 07:50:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56486#M12067</guid>
      <dc:creator>lu</dc:creator>
      <dc:date>2009-07-23T07:50:19Z</dc:date>
    </item>
    <item>
      <title>Re: File name automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56487#M12068</link>
      <description>put cmd=;&lt;BR /&gt;
    rc=system(cmd);&lt;BR /&gt;
   end;&lt;BR /&gt;
run;&lt;BR /&gt;
lu.&lt;BR /&gt;
&lt;BR /&gt;
P.S bug in forum ??? cut my previous message

Message was edited by: lu</description>
      <pubDate>Thu, 23 Jul 2009 07:55:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56487#M12068</guid>
      <dc:creator>lu</dc:creator>
      <dc:date>2009-07-23T07:55:55Z</dc:date>
    </item>
    <item>
      <title>Re: File name automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56488#M12069</link>
      <description>Thanks Lu!</description>
      <pubDate>Thu, 23 Jul 2009 14:47:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56488#M12069</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2009-07-23T14:47:35Z</dc:date>
    </item>
    <item>
      <title>Re: File name automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56489#M12070</link>
      <description>Question.&lt;BR /&gt;
How to change the tab name?</description>
      <pubDate>Thu, 23 Jul 2009 18:26:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56489#M12070</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2009-07-23T18:26:04Z</dc:date>
    </item>
    <item>
      <title>Re: File name automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56490#M12071</link>
      <description>What about Daniel Santos's answer ?&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/message.jspa?messageID=23303#23303" target="_blank"&gt;http://support.sas.com/forums/message.jspa?messageID=23303#23303&lt;/A&gt;&lt;BR /&gt;
lu</description>
      <pubDate>Thu, 23 Jul 2009 20:47:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56490#M12071</guid>
      <dc:creator>lu</dc:creator>
      <dc:date>2009-07-23T20:47:34Z</dc:date>
    </item>
    <item>
      <title>Re: File name automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56491#M12072</link>
      <description>Hi Daniel,&lt;BR /&gt;
 I used your code in the bottom half(comments added) and it throws an error:&lt;BR /&gt;
The top part is working fine.It chages the file name.The tab should be changed to &lt;BR /&gt;
what ever value is passed to nm_2009_month (in this case nm='Pharmacare';)&lt;BR /&gt;
Pharmacare_2009_06.&lt;BR /&gt;
error shown in the end of the code:&lt;BR /&gt;
&lt;BR /&gt;
options noxwait;&lt;BR /&gt;
%let my_dir=C:\Documents and Settings\skap\Desktop\inpt;&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
 dir_cmd='dir "'||"&amp;amp;my_dir"||'"';&lt;BR /&gt;
 rc=filename('dir',dir_cmd,'pipe');&lt;BR /&gt;
 run;&lt;BR /&gt;
&lt;BR /&gt;
data d;&lt;BR /&gt;
infile dir pad truncover;&lt;BR /&gt;
input date $10.@;&lt;BR /&gt;
if date ='' or date='Volume' or length(date) &amp;lt;10 then  delete;&lt;BR /&gt;
else input  time $ ampm $ dir $ name $200.;&lt;BR /&gt;
if trim(dir)='&lt;DIR&gt;' then delete;&lt;BR /&gt;
if index(name,'Norditropin Pharmacare') then&lt;BR /&gt;
  do;&lt;BR /&gt;
   nm='Pharmacare';&lt;BR /&gt;
   cmd='ren "'||"&amp;amp;my_dir\"||trim(left(name)) ||'" "'||compress(left(nm)||'_'||year(today())||'_'||put(month(today()),z2.)||'.xls"') ;&lt;BR /&gt;
   put cmd=;&lt;BR /&gt;
   rc=system(cmd);&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/*** Daniel's code starts here ***/&lt;BR /&gt;
* start Excel DDE server;&lt;BR /&gt;
x 'C:\Documents and Settings\skap\Desktop\inpt'; /* you may need to add the full path */&lt;BR /&gt;
&lt;BR /&gt;
filename xlfile dde 'excel|system';&lt;BR /&gt;
data _null_;&lt;BR /&gt;
file xlfile; * start DDE connection and open desired workbook;&lt;BR /&gt;
put '[OPEN("&amp;amp;my_dir.\&amp;amp;FILENAME..xls")]'; /* replace with your &lt;DIR&gt; */&lt;BR /&gt;
put '[WORKBOOK.NEXT()]';&lt;BR /&gt;
put '[WORKBOOK.INSERT(3)]'; * insert new macro worksheet;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
* prepare macro for worksheet renaming;&lt;BR /&gt;
filename xlmacro dde 'excel|Macro1!r1c1:r2c1' notab;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
file xlmacro;&lt;BR /&gt;
* write macro code;&lt;BR /&gt;
put '=WORKBOOK.NAME("Sheet1","&amp;amp;FILENAME")';&lt;BR /&gt;
put '=HALT(TRUE)';&lt;BR /&gt;
put '!dde_flush';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
* rename worksheet by running macro;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
file xlfile;&lt;BR /&gt;
put '[RUN("Macro1!r1c1")]';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
* delete macro worksheet;&lt;BR /&gt;
filename xlmacro clear;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
file xlfile;&lt;BR /&gt;
put '[WORKBOOK.ACTIVATE("Macro1")]';&lt;BR /&gt;
put '[ERROR(FALSE)]';&lt;BR /&gt;
put '[WORKBOOK.DELETE()]';&lt;BR /&gt;
put '[ERROR(TRUE)]';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
ERROR: Physical file does not exist, excel|system.&lt;/DIR&gt;&lt;/DIR&gt;</description>
      <pubDate>Fri, 24 Jul 2009 18:30:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/File-name-automation/m-p/56491#M12072</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2009-07-24T18:30:05Z</dc:date>
    </item>
  </channel>
</rss>

