In this tutorial we will learn how to Execute Operating System Commands from Your SAS Session Using MACRO.In this session we’re going to create a macro function which is going to be used to execute Unix/Linux commands through SAS EG session.
Execute Operating System Commands from Your SAS Session
In this example we will create a macro and then we used this macro to list the files of current working directory from SAS EG.
/* Macro Definition */ %MACRO CMD(INPUT); %LET INPUTCMD = &INPUT; FILENAME IN PIPE &INPUTCMD.; DATA _NULL_; INFILE IN; INPUT; PUT _INFILE_; RUN; %MEND CMD; /* Macro Calling*/ %CMD('ls -ltr');
If you don’t want to create macro then you can directly execute operating system command using below code:
FILENAME IN PIPE "<Specify Command >"; DATA _NULL_; INFILE IN; INPUT; PUT _INFILE_; RUN;
Note : This Macro will only work for Unix/Linux enviroment and make sure while calling macro you’re passing values in small case as you know unix and linus os are case sensitive.
Happy Learning !!