Thursday, March 26, 2015

SAS: FTP an external file (flat file)

I had a lot of trouble with SAS' FTP access engine. It appeared to be randomly corrupting the data.  This worked though. I relied heavily on the indicated web page, and then converted it to a macro.


* ----------------------------------------------------- ;
*              M A C R O :  F T P F I L E
* ----------------------------------------------------- ;
*  FTP the hard way...but to overcome failure of the
*  FTP access engine, which corrupted the data.
*  Source: https://communities.sas.com/message/114111
*  Bill Qualls, 20150326
* ----------------------------------------------------- ;

%macro ftpfile(folder=&RAWDATA_FOLDER, file=, ftpcom=&RAWDATA_FOLDER/ftpcom.txt);

* file to which ftp commands will be written ;
filename ftpcom "&FTPCOM" lrecl=80;

data _null_;
file ftpcom;

* ftp ession user and password ;
put "user theuser thepassword";

* disable prompting cmd ;
put "prom no";

* enable binary transfer mode cmd ;
put "bin";

* go to local folder cmd ;
put "lcd &FOLDER";

* go to remote folder cmd ;
put "cd OurFolderOnFTPServer";

* send file cmd ;
put "send &file";

run;


* set up piping into ftp commands into ftp instruction ;
filename doftp pipe "ftp -n ftp.xxxxxxxx.com < &FTPCOM";


* enable ftp session and pass it the commands file ;
data _null_;
infile doftp;
input;
put _infile_;
run;

%mend ftpfile;

Monday, March 23, 2015

Linux: Zipping files in Linux

My co-worker Ken shared this with me.



Here is how I am zipping files:

First, navigate to the directory where the files are located. Then, 

zip –mT  abc  abc*

This creates the archive abc.zip, then adds to it all files in the current directory named like abc*, then tests the archive (the T option), then if test is OK, deletes the files (effectively moving the files to the zip archive (the –m option)).





Saturday, March 14, 2015

SAS: FTP as SAS dataset as a SAS dataset

When I FTP from SAS it is usually a CSV file. Client needed a SAS file FTPed.  Here's how.  Note you actually have to refer to the full path name and file name, including the .sas7bdat extension, locally and on the FTP server.


  FILENAME FTPOUT FTP "/ftp/path/target.sas7bdat"
      host="ftp.xxxxxx.com"
      user="xxxxxx"
      pass="xxxxxx"
      RCMD='site umask 022'
      RECFM=S DEBUG;

  DATA _NULL_;
     INFILE "/sas/path/source.sas7bdat" RECFM=F;
     FILE FTPOUT;
     INPUT;
     PUT _INFILE_;
  RUN;





Monday, March 9, 2015

Linux: uptime command



A scheduled process stopped running. I wondered if perhaps the server had been shut down. Turns out there is a Linux command to check that: uptime.

   [xcnb804@omhq1845 scripts]$ uptime
    08:51:35 up 27 days, 38 min,  4 users,  load average: 0.06, 0.10, 0.37
   [xcnb804@omhq1845 scripts]$


About the command: http://linux.about.com/library/cmd/blcmdl1_uptime.htm

Unfortunately, server had not been shut down, so I still don't know the root cause of my problem....