<?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 Filename ftp (How to set to VARIABLE for file name) in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Filename-ftp-How-to-set-to-VARIABLE-for-file-name/m-p/108181#M30122</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Trying to write multiple text files to a server by the FTP method.&amp;nbsp; I can get 1 file to write to the server I want to write to, but I would like to write different text files, using the name field in the dataset to set the name of the text file.&lt;/P&gt;&lt;P&gt;Example dataset call testing:&lt;/P&gt;&lt;P&gt;obs name lastname&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bob&amp;nbsp;&amp;nbsp; smith&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sandy lane&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp; luke&amp;nbsp;&amp;nbsp; rath&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Would like to have the following text files created:&lt;BR /&gt;bob.txt&lt;/P&gt;&lt;P&gt;sandy.txt&lt;/P&gt;&lt;P&gt;luke.txt&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code I have...I have tried a lot of different things, this is the latest.&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;set testing end=eof;&lt;/P&gt;&lt;P&gt;by name;&lt;/P&gt;&lt;P&gt;if first.name then do;&lt;/P&gt;&lt;P&gt;fname="'"||trim(left(put(name,$10.)))||".txt'";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;filename create ftp "&amp;amp;fname"' cd='host_dir'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; host='hostname'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; user='test1'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pass='xxxxxx'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; recfm=v;&lt;/P&gt;&lt;P&gt;file create linesize=155;&lt;/P&gt;&lt;P&gt;put @1 "&amp;lt;firstname="""name""" lastname="""lastname"""&amp;gt;;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I replace &amp;amp;fname with 'testing.txt'&amp;nbsp; I get one file with all the data in it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a way to do this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Tony&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 26 Oct 2012 16:34:45 GMT</pubDate>
    <dc:creator>tony146</dc:creator>
    <dc:date>2012-10-26T16:34:45Z</dc:date>
    <item>
      <title>Filename ftp (How to set to VARIABLE for file name)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Filename-ftp-How-to-set-to-VARIABLE-for-file-name/m-p/108181#M30122</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Trying to write multiple text files to a server by the FTP method.&amp;nbsp; I can get 1 file to write to the server I want to write to, but I would like to write different text files, using the name field in the dataset to set the name of the text file.&lt;/P&gt;&lt;P&gt;Example dataset call testing:&lt;/P&gt;&lt;P&gt;obs name lastname&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bob&amp;nbsp;&amp;nbsp; smith&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sandy lane&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp; luke&amp;nbsp;&amp;nbsp; rath&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Would like to have the following text files created:&lt;BR /&gt;bob.txt&lt;/P&gt;&lt;P&gt;sandy.txt&lt;/P&gt;&lt;P&gt;luke.txt&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code I have...I have tried a lot of different things, this is the latest.&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;set testing end=eof;&lt;/P&gt;&lt;P&gt;by name;&lt;/P&gt;&lt;P&gt;if first.name then do;&lt;/P&gt;&lt;P&gt;fname="'"||trim(left(put(name,$10.)))||".txt'";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;filename create ftp "&amp;amp;fname"' cd='host_dir'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; host='hostname'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; user='test1'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pass='xxxxxx'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; recfm=v;&lt;/P&gt;&lt;P&gt;file create linesize=155;&lt;/P&gt;&lt;P&gt;put @1 "&amp;lt;firstname="""name""" lastname="""lastname"""&amp;gt;;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I replace &amp;amp;fname with 'testing.txt'&amp;nbsp; I get one file with all the data in it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a way to do this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Tony&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Oct 2012 16:34:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Filename-ftp-How-to-set-to-VARIABLE-for-file-name/m-p/108181#M30122</guid>
      <dc:creator>tony146</dc:creator>
      <dc:date>2012-10-26T16:34:45Z</dc:date>
    </item>
    <item>
      <title>Re: Filename ftp (How to set to VARIABLE for file name)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Filename-ftp-How-to-set-to-VARIABLE-for-file-name/m-p/108182#M30123</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not 100% sure if below code will work. Give it a try and let us know.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Alternatively you could write all your files to a folder using the file statement in comment in below code and then use a FTP with mput to transfer all files in this folder.&lt;/P&gt;&lt;P&gt;If your data is not sorted by "name" and there are multiple rows with the same name then you might also need to use the "mod" option for the file statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;&amp;nbsp; input name $ lastname $;&lt;BR /&gt;&amp;nbsp; datalines;&lt;BR /&gt;bob smith&lt;BR /&gt;sandy lane&lt;BR /&gt;luke rath&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;&amp;nbsp; set have;&lt;BR /&gt;&amp;nbsp; length outfile $1000;&lt;/P&gt;&lt;P&gt;/*&lt;BR /&gt;&amp;nbsp; outfile=cats('c:\test\',name,'.txt');&lt;BR /&gt;&amp;nbsp; file dummy filevar=outfile;&lt;/P&gt;&lt;P&gt;*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; outfile=cats('&amp;lt;host_dir&amp;gt;',name,'.txt');&lt;BR /&gt;&amp;nbsp; file dummy ftp&amp;nbsp; filevar=outfile&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; host='hostname'&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; user='test1'&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; pass='xxxxxx'&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; recfm=v &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; linesize=155;&lt;BR /&gt;&amp;nbsp; put name +(-1) ',' lastname;&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Oct 2012 23:29:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Filename-ftp-How-to-set-to-VARIABLE-for-file-name/m-p/108182#M30123</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2012-10-26T23:29:28Z</dc:date>
    </item>
    <item>
      <title>Re: Filename ftp (How to set to VARIABLE for file name)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Filename-ftp-How-to-set-to-VARIABLE-for-file-name/m-p/108183#M30124</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="http://www.nesug.org/Proceedings/nesug99/ad/ad090.pdf" title="http://www.nesug.org/Proceedings/nesug99/ad/ad090.pdf"&gt;http://www.nesug.org/Proceedings/nesug99/ad/ad090.pdf&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 27 Oct 2012 10:17:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Filename-ftp-How-to-set-to-VARIABLE-for-file-name/m-p/108183#M30124</guid>
      <dc:creator>Howles</dc:creator>
      <dc:date>2012-10-27T10:17:50Z</dc:date>
    </item>
    <item>
      <title>Re: Filename ftp (How to set to VARIABLE for file name)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Filename-ftp-How-to-set-to-VARIABLE-for-file-name/m-p/108184#M30125</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually the advice in that presentation is out of date. The FILEVAR option on the FILE statement does work with the FTP method.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data _null_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; set testing ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; fname = catx('.',name,'txt');&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; file create &lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;ftp&lt;/SPAN&gt; linesize=155 filevar=fname&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cd='host_dir'&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; host='hostname'&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; user='test1'&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; pass='xxxxxx'&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; recfm=v&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; put @1 '&amp;lt;firstname=' name : $quote. 'lastname=' lastname : $quote. '&amp;gt;';&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Note that the put statement could be even simpler if the dataset variable names matched the field names in your output text file.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data _null_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; length firstname lastname $20;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; input firstname lastname ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; put '&amp;lt;' (firstname lastname) (= : $quote.) '&amp;gt;' ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;cards;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;bob smith&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;sam jones&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 27 Oct 2012 12:48:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Filename-ftp-How-to-set-to-VARIABLE-for-file-name/m-p/108184#M30125</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-10-27T12:48:59Z</dc:date>
    </item>
    <item>
      <title>Re: Filename ftp (How to set to VARIABLE for file name)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Filename-ftp-How-to-set-to-VARIABLE-for-file-name/m-p/108185#M30126</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would like do it respectively . First make these txt file ,then using command to ftp them up to SAS Server.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data x;
input obs name $ lastname $;
cards;
1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bob&amp;nbsp;&amp;nbsp; smith
2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sandy lane
3&amp;nbsp;&amp;nbsp;&amp;nbsp; luke&amp;nbsp;&amp;nbsp; rath
;
run;
proc sql;
create table temp as
 select distinct name from x;
quit;
data _null_;
 set x;
 *output all of txt file under c:\temp\ ;
 call execute(catt('proc export outfile="c:\temp\',name,'.txt" data=x(where=(name="',name,'")) dbms=tab replace;run;'));
run;




Then 
cd c:\temp\
ftp 10.1.66.14
enter your username and password
&amp;gt;binary
&amp;gt;prompt
&amp;gt;mput *.txt 

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Oct 2012 02:49:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Filename-ftp-How-to-set-to-VARIABLE-for-file-name/m-p/108185#M30126</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-10-29T02:49:29Z</dc:date>
    </item>
  </channel>
</rss>

