Unix for SAS Analysts

 

Unix version of SAS is commonly used in organizations with large number of users. Additionally, PC SAS and its Remote SUBMIT features are used to connect to Unix SAS. While working with Unix SAS an analyst or SAS Programmer should be comfortable with a  few Unix  navigation and utility commands that enables him/her to work independently and efficiently. Here are some topics I thought would be useful.

Where and how typically Unix is used :

  • Mostly the  servers are Unix based  with an ip address  (e.g 3.172.21.66). SAS will be installed in this server and also some facility for file storage.
  • Mostly Databases/warehouses are in UNIX servers – Oracle and SAS based data warehouses.
  • SAS in Unix Server  using  Signon,  Rsubmit, and batch execution etc.
  • Files/datasets  are uploaded and downloaded to and from Unix Servers(server folders)

Unix Server Spaces or Remote Storage

Many a times the data is permanently stored in one of the Unix servers. One should know how to use a library function to store and retrieve a dataset in unix. For example, if the allocated space is in  ‘/projects/dual_cards/jkurian ‘, to save or retrieve a SAS dataset into this location, you need to  declare a library name in SAS program as follows:

Libname rloc '/projects/dual_cards/jkurian';

proc datasets lib=rloc;run;

Proc datasets will list all the datasets in this location.

Note that in Unix, the ‘/’ sing is used to separate the directories.  Reverse is the case when you work with windows.

SASWORK  in UNIX

‘Saswork’ is a location in Unix (server space) where SAS does the data processing by default. It’s a shared space where each SAS Unix user is allocated with space to process their request. Typically the size of SASwork runs into 100 plus GBs but due to the number of users and volume of data used, this space gets consumed very fast.  Exhausting this space can lead to terminating all the SAS program submitted by multiple users hence it’s a responsibility of an analyst to monitor this space.  

Let us learn 15 Unix commands listed below. These commands are commonly used in consumer finance  environment and meet 90% of the  requirements while working with Unix SAS.

A List of Useful UNIX Commands

pwd:  to see what’s the  present working directory

Usage:  /home/jkurian> pwd

ls  : Lists the files and folders

ls –l : detailed listing of files and directories

Wildcard usage: ls –l *. sas7*

Usage:  /home/jkurian> ls –l

mkdir : make a directory

Usage:  mkdir <filename>

cd : change into a directory

Usage: cd <folder Name>

cp : to copy a files/directory

Usage: cp <filename>  <folder name/filename>

rmdir: remove a directory

rm : remove a file

rm  -R  : Remove files and directories, recursively, empty or not

cat  : to read a text file (csv, sas pgm etc) .prints the contents to the screen

chmod : Change file attributes (Read / Write / Executable for owner, group & others)

Usage: chmod 777 <filename/folder name>

Tips: 777- all access, 775 – all access to the group, 700- protect files

gzip  : to compress a file

Usage:  gzip <filename>

gunzip: Unzips the files that are compressed

Usage: gunzip <filename>

grep – a very powerful text searching command. Always used when we want to list the files created by a user or space utilization.

Usage 1: ls -l | grep jkurian – returns all files created by jkurian

Usage 2: grep ‘jkurian’  *.sas – lists lines where there is a ‘jkurian’ occurrence anywhere inside the  .SAS files

ps  -ef   - Lists the processes currently running. Useful when we want to kill some program we submitted.

Usage: ps  -ef  | grep <user id>  lists all the process id for that particular user. Process ID or PIDs are required to kill a particular process.

kill –9  - Kills a specified process that’s submitted  by the user.

Usage : kill –9  <PID>  - PID Obtained by using ‘ps’ command.

df  -k .  Shows the space utilized and space available for the root folder. Helpful to estimate the space availability. Space is showed in kilobytes.

 

Steps to see the SASWORK space availability

    1. Telnet/Logon to the Server (unix sever of your business)
    2. Issue command ‘cd  /saswork’  - if /saswork is the work folder
    3. Issue command ‘df –k .’

The space utilization would be printed to the screen. Don’t submit a program unless there is enough space free (At least 10% free)

Steps to know how many folders are created  in SASWORK

  1. Telnet/Logon to the Server (your business's server)
  2. Issue command ‘cd  /saswork’ 
  3. Issue command ls –l | grep ‘jkurian’

Substitute your username instead of ‘jkurian’, to get of folders created by you in SAS work.  Its important to clean up the dead or orphan processes in your SASwork to optimize the saswork space.

Steps to remove a folder in SASWORK that’s no more required

  1. Go to /saswork
  2. Issue command ls –l | grep ‘jkurian’  to see the folders created by you
  3. Issue command rm –R <foldername>  to remove the entire folder.

If you want to remove only files inside a folder, do ‘cd’ into that folder and use ‘rm <filename> ‘ command to remove the file.

FTP and How to work with it

File transfer protocol- we use ftp utility/command to transfer files (sas pgms, datasets, text outputs) between servers and also to upload and download between desktop and servers.

FTP from desktop - Go to START/RUN and type ftp <remote server name/ip>  (Just like telnet)

FTP between two Unix servers (say two unix servers in your business) - Issue ‘ ftp <ip address>‘ command in the Unix shell prompt.

 Commonly Used FTP commands:

put : put <filename>

get : get <file name>

mput: mput *.sas –matches the pattern

mget: mget *.sas

prompt: turns the prompt off

bin: sets the transfer mode to binary- use it for excel, datasets etc

lcd : change local directory path

pwd : see present working directory

ls: list files and folders in the remote server.

 

Steps to run a SAS program in a Telnet Session (Unix Server)

First create a SAS program and store it in one of the Unix folders OR FTP a program from the desktop. At the shell prompt issue the following command

nohup sas <filename>  &

For example:

/home/jkurian> nohup sas scoretest.sas &

nohup:  to protect from hang ups – you can close the telnet window and the program would be still running!

Sas: key word to invoke SAS program to execute the program

&: Running the program in background – you can continue work in the same terminal

You can locate the log and output files within the same directory as you submitted the program.

Copyright free public information. All trademarks,service marks, logos and names are properties of their respective owners.