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:
*  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";


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

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

%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, 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"
      RCMD='site umask 022'

     INFILE "/sas/path/source.sas7bdat" RECFM=F;
     PUT _INFILE_;

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:

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