SAS宏到PC和Unix之间或Unix服务器位置之间的FTP文件。。。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SAS宏到PC和Unix之间或Unix服务器位置之间的FTP文件。。。相关的知识,希望对你有一定的参考价值。

  1. %macro ftpfile(localfile,localdir,remotefile,remotedir,remotehost,ftpcommand);
  2.  
  3. options comamid=tcp nosymbolgen;
  4. filename sasparm "!mysasfilessasparm"; /*location of a file containing the username and password for access */
  5.  
  6. %global rmtuser rmtpw rc;
  7.  
  8. /* read in the username and password and create macrovars rmtuser rmtpw*/
  9. data _null_;
  10. length rmtuser rmtpw $30.;
  11. infile sasparm;
  12. input rmtuser $
  13. rmtpw $
  14. ;
  15. call symput('rmtuser',trim(rmtuser));
  16. call symput('rmtpw',trim(rmtpw));
  17. run;
  18.  
  19. /* Set a filename FTP statement to remote file */
  20. filename rmfile ftp "&remotefile" cd="&remotedir." host="&remotehost." user="&rmtuser." pass="&rmtpw.";
  21.  
  22. %if &ftpcommand = get %then /*i.e. download remotefile to the Local file */
  23. %do;
  24.  
  25. /* Check if the file exists */
  26. %let rc=%sysfunc(fexist(rmfile));
  27. %*****If unable to establish a filename, send error stop;
  28. %if (&rc eq 0)%then
  29. %do;
  30. %put ******Unable to establish FTP connection to file--&rc.;
  31. %put ******Problem with input file: &remotefile.;
  32. %let rc= -1;
  33. %end;
  34. %else
  35. %do;
  36. %put ******Establish FTP connection to file--&remotefile;
  37.  
  38. data _null_;
  39. infile rmfile;
  40. file "&localdir./&localfile.";
  41. input;
  42. put _infile_;
  43. run;
  44.  
  45. %let filrf=lclfile;
  46. %let rc=%sysfunc(filename(filrf,"&localdir./&localfile."));
  47. %end;
  48. %end;
  49. %else %if &ftpcommand = put %then
  50. %do;
  51. /* Check if the file exists */
  52. %let filrf=lclfile;
  53. %let rc=%sysfunc(filename(filrf,"&localdir./&localfile."));
  54. %if &rc ne 0 %then
  55. %do;
  56. %put %sysfunc(sysmsg());
  57. %end;
  58. %else
  59. %do;
  60. data _null_;
  61. infile "&localdir./&localfile.";
  62. file rmfile;
  63. input;
  64. put _infile_;
  65. run;
  66.  
  67. /* Check if the file exists */
  68. %let rc=%sysfunc(fexist(rmfile));
  69. %end;
  70. %end;
  71.  
  72. %put ftp returncode:&rc;
  73.  
  74. /* Abort the job with rc=16 for batch processes...
  75.   Remove this line if you are using it in interactive sas..else your session will be ended
  76. */
  77. %if &rc ne 0 %then %abort return 16;
  78.  
  79. %mend ftpfile;
  80.  
  81. /* FTP test.sas from desktop to test1.sas on unix server */
  82.  
  83. %ftpfile(test.sas,C:,test1.sas,/data/dev/sastechies/sas,server,put);
  84.  
  85.  
  86. /* FTP test1.sas from Server to test1.sas on Desktop */
  87.  
  88. %ftpfile(test1.sas,C:,test1.sas,/data/dev/sastechies/sas,server,get);

以上是关于SAS宏到PC和Unix之间或Unix服务器位置之间的FTP文件。。。的主要内容,如果未能解决你的问题,请参考以下文章

使用 UNIX SAS 找出 Netezza 表的大小

在PC中运行的IDE与后端UNIX机器中的代码之间的代码同步

dos和unix换行符解析

使用 UNIX SAS 确定 Netezza DISTRIBUTE_ON 键

linux知识

#yyds干货盘点#网络协议之:socket协议详解之Unix domain Socket