SlideShare ist ein Scribd-Unternehmen logo
1 von 33
Downloaden Sie, um offline zu lesen
UNIX X Command Tips and Tricks
David B. Horvath, CCP, MS
PhilaSUG Winter 2019
TD Bank, Wilmington DE
March 19, 2019
2
UNIX X Command Tips and Tricks
The Author can be contacted at:
504 Longbotham Drive, Aston PA 19014-2502, USA
Phone: 1-610-859-8826
Email: dhorvath@cobs.com
Web: http://www.cobs.com/
All trademarks and servicemarks are the
property of their respective owners.
Copyright © 2019 David B. Horvath, CCP — All Rights Reserved
Abstract
SAS provides the ability to execute operating system level commands from
within your SAS code – generically known as the “X Command”. This session
explores the various commands, the advantages and disadvantages of each,
and their alternatives. The focus is on UNIX/Linux but much of the same applies
to Windows as well. Under SAS EG, any issued commands execute on the SAS
engine, not necessarily on the PC.
• X
• %sysexec
• Call system
• Systask command
• Filename pipe
• &SYSRC
• Waitfor
Alternatives will also be addressed – how to handle when NOXCMD is the
default for your installation, saving results, and error checking.
3
4
My Background
• David is an IT Professional who has worked with various platforms
since the 1980’s with a variety of development and analysis tools.
• He has presented at PhilaSUG, SESUG, and SGF previously and has
presented workshops and seminars in Australia, France, the US,
Canada, and Oxford England (about the British Author Nevil Shute) for
various organizations.
• He holds an undergraduate degree in Computer and Information
Sciences from Temple University and a Masters in Organizational
Dynamics from UPENN. He achieved the Certified Computing
Professional designation with honors.
• Most of his career has been in consulting (although recently he has
been in-house) in the Philadelphia PA area. He is currently in Data
Analytics "Engineering" at a Regional Bank.
• He has several books to his credit (none SAS related) and is an
Adjunct Instructor covering IT topics for University of Phoenix.
5
Options
• Execution of any System command from within your SAS program is
dependent on one option's setting:
XCMD Enables the X command in SAS.
• Which can only be set at startup:
options xcmd;
____
30
WARNING 30-12: SAS option XCMD is valid only at
startup of the SAS System. The SAS option is ignored.
• If NOXCMD is set, you're out of luck. Sorry!
• University Edition is NOXCMD
6
X
• The basic X Command
• Runs independent of data steps and macros
• The SAS Engine will interpret some commands
• Does not spawn off sub-process
• This fact is important because information does not persist between sub-
processes
• Handling within the log is annoying
7
X
• X Command Examples:
• pwd and cd under UNIX:
NOTE: Current working directory is
'/this/is/the/sas/install/directory'.
26 x "pwd" ; /* works within SAS */
27 x "cd /my/directory/is/here"
27 ! ; /* works within SAS */
NOTE: Current working directory is '/my/directory/is/here'.
28 x "pwd" ; /* works within SAS */
• echo and combined commands under UNIX:
29 x "echo $HOME"
29 ! ; /* works but no output */
30 x "pwd; cd $HOME; pwd"
30 ! ; /* no output, works? */
8
X
• X Command Examples:
• We can combine commands on one line under UNIX:
31 x 'echo start; echo mid; echo end>temp2.txt'
31 ! ; /* output to file, works */
• > sends STDOUT to a file
• I know this works because I can look at the output file (temp2.txt):
end
• Why didn't "start" and "mid" appear?
• Because of the way I wrote the statement!
9
X
• X Command Examples:
• We can combine commands on one line under UNIX:
37 x '(echo start; echo mid; echo end)>temp1.txt'
37 ! /* output to file, all 3 statements to file */
• I know this works because I can look at the output file (temp1.txt):
start
mid
end
• The difference is the parenthesis which combines the output in UNIX
• Because of the way I wrote the statement!
10
X and %SYSRC
• How do I know a command worked?
• %SYSRC will tell me – returns the UNIX error code
37 x '(echo start; echo mid; echo end)>temp1.txt'
37 ! ; /* output to file, all 3 statements to file */
SYMBOLGEN: Macro variable SYSRC resolves to 0
38 %put &SYSRC;
0
• Zero is success in UNIX
• If the command does not exist, we get 127:
39 x 'this_command_doesnot_exist'
39 ! ; /* non-zero RC */
SYMBOLGEN: Macro variable SYSRC resolves to 127
40 %put &SYSRC;
127
11
X and %SYSRC
• How do I know a command worked?
• If the command does not exist, we get 127:
41 x 'this_command_doesnot_exist 2>test5.txt'
41 ! ; /* non-zero RC */
SYMBOLGEN: Macro variable SYSRC resolves to 127
42 %put &SYSRC;
127
• And we can save error output (2> sends STDERR to a file):
/bin/bash: this_command_doesnot_exist: command not found
43 x 'ls -al no_such_file'
43 ! ; /* non-zero RC */
SYMBOLGEN: Macro variable SYSRC resolves to 2
44 %put &SYSRC;
2
12
X and %SYSRC
• How do I know a command worked?
• The command itself may return an error as well:
43 x 'ls -al no_such_file'
43 ! ; /* non-zero RC */
SYMBOLGEN: Macro variable SYSRC resolves to 2
44 %put &SYSRC;
2
• In this case, "no_such_file" does not exist
• 'man ls' executed at the command line will provide this information
Exit status:
0 if OK,
1 if minor problems (e.g., cannot access subdirectory),
2 if serious trouble (e.g., cannot access command-line argument).
13
%sysexec – Macros
• We can execute system commands within a macro:
72 %macro commands;
73 %sysexec %str(ls -al > test6.txt);
74 %put &SYSRC;
75 %sysexec %str(command_doesnot_exist 2>
test7.txt);
76 %put &SYSRC;
77 %mend commands;
78
79 %commands;
• Note the use of %SYSRC
14
%sysexec – Macros
• And get the following results:
79 %commands;
MLOGIC(COMMANDS): Beginning execution.
MLOGIC(COMMANDS): %SYSEXEC ls al test6.txt
MLOGIC(COMMANDS): %PUT &SYSRC
SYMBOLGEN: Macro variable SYSRC resolves to 0
0
MLOGIC(COMMANDS): %SYSEXEC command_doesnot_exist 2
test7.txt
MLOGIC(COMMANDS): %PUT &SYSRC
SYMBOLGEN: Macro variable SYSRC resolves to 127
127
MLOGIC(COMMANDS): Ending execution.
15
Call System – Data Step
• Use Call System within a data step:
85 data dir;
86 filename commands PIPE "ls | head -2";
87 infile commands truncover;
88 input result $char60.;
89
90 string="echo " || result || " >> test4.txt";
91 call system(string); /* no output - but it executes
multiple times */
92 system_rc=symget("SYSRC");
93 call system("this_command_doesnot_exist");
94 system_rc2=symget("SYSRC");
95
96 systask command "pwd" wait shell; /* runs once */
NOTE: LOG/Output from task "task59"
> /my/directory/is/here
NOTE: End of LOG/Output from task "task59"
97 output;
98 run;
16
Call System – Data Step
• Call System results:
NOTE: The infile COMMANDS is:
Pipe command="ls | head -2"
NOTE: 2 records were read from the infile COMMANDS.
The minimum record length was 22.
The maximum record length was 24.
NOTE: The data set WORK.DIR has 2 observations and 4 variables.
NOTE: Compressing data set WORK.DIR increased size by 100.00
percent.
Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.00 seconds
17
Call System – Data Step
• Call System output:
• Results:
• Test4.txt:
FILE1
FILE2
• Two records were read from infile
• Two records were written to work.dir
• Two records were written to test4.txt via the echo command
• SAS Engine does not interpret these commands
Obsresult string system_rc system_rc2
1FILE1 echo FILE1 >> test4.txt 0 127
2FILE2 echo FILE2 >> test4.txt 0 127
18
'Systask command'
• 'Systask command' operates two modes:
• With "shell" modifier, SAS does not interpret the commands
• Without "shell", it behaves like X
• &SYSRC is set
54 systask command 'echo BOL $HOME EOL' wait;
NOTE: LOG/Output from task "task62"
> BOL $HOME EOL
NOTE: End of LOG/Output from task "task62"
54 ! /* $HOME not interpreted */
55 systask command "echo BOL $HOME EOL" wait shell;
NOTE: LOG/Output from task "task63"
> BOL /my/directory/is/here EOL
NOTE: End of LOG/Output from task "task63"
55 ! /* $HOME interpreted */
19
'Systask command' and 'Systask list'
• Other Options:
• Wait: wait for this command to execute before starting next
• Cleanup: wait for this command and any nowait before starting next
• Shell: Can also specify the shell to use: shell="/usr/bin/ksh"
• Status: Can specify a status variable to check later (rather than &SYSRC)
• Taskname: Can specify task name for later use in Waitfor
• Systask list will provide status of any nowait systasks
"task150" --------------
Type: Task
State: COMPLETE
Status Macro Variable: Unspecified
73
74 systask list;
20
'Systask command' and 'Waitfor'
• The waitfor command is used to wait for systask command nowait to
complete
• Can wait for _ANY_ of listed tasknames to complete (default)
• Can wait for _ALL_ of listed tasknames to complete
• Can specify length of time to wait: Timeout=number-of-seconds
• General form is
waitfor _ALL_ task1 task2 task3;
21
Filename pipe
• Acts like normal filename statement
• Accepts data written from SAS (File/Put)
• Provides data for SAS to read (Infile/Input)
• Allows for execution of UNIX command
• Is more efficient than running command separately (parallelization)
• Handy when you have version limitations:
filename gzipit zip '/my/output/directory/file.txt.gz' gzip;
* requires 9.4M5;
filename gzipit pipe 'gzip -c >
/my/output/directory/file.txt.gz'; * run the UNIX gzip;
22
Filename Pipe – Earlier Code Example
• UNIX Commands are Executed prior to input statement:
85 data dir;
86 filename commands PIPE "ls | head -2";
87 infile commands truncover;
88 input result $char60.;
89
90 string="echo " || result || " >> test4.txt";
91 call system(string); /* no output - but it executes
multiple times */
92 system_rc=symget("SYSRC");
93 call system("this_command_doesnot_exist");
94 system_rc2=symget("SYSRC");
95
96 systask command "pwd" wait shell; /* runs once */
NOTE: LOG/Output from task "task59"
> /my/directory/is/here
NOTE: End of LOG/Output from task "task59"
97 output;
98 run;
23
Filename Pipe
• Unfortunately, &SYSRC is not set by Filename Pipe:
113 data baddir;
114 filename commands PIPE "lx ; lx ; lx";
115 system_rc=symget("SYSRC");
116
117 infile commands truncover;
118 input result $char60.;
119 output;
120 run;
NOTE: The infile COMMANDS is:
Pipe command="lx ; lx ; lx"
NOTE: 3 records were read from the infile COMMANDS.
The minimum record length was 32.
The maximum record length was 32.
24
Shell Scripts
• When NOXCMD is set, none of these will work.
• You can move the commands into a shell script:
#!/bin/ksh
cd /desired/directory
# You can check return codes here with the $?
if [[ $? -gt 0 ]]; then
echo "cd failed"
exit 3
fi
# if we get here 'cd' succeeded
ls –al | head -2 > temp.txt
sas your_sas_part_1.sas
pwd
sas your_sas_part_2.sas
gzip /my/output/directory/file.txt
25
Final Thoughts
• It is all about choices
• Sometimes it is better to execute UNIX commands in your program
• Sometimes not
26
Wrap Up
Questions
and
Answers
?! ?!
?! ?!
?
? ?
?
!
!
!
!
27
Named Pipes under UNIX – Filename Pipe with NOXCMD
• I can use UNIX “Named Pipes” with files
• Datasets make use of the "Sequential Data Engine" ("TAPE" engine)
• External Command Example – Write:
• UNIX/Linux commands:
mknod mypipe p
gzip –c mypipe > input.gz & /* runs in background */
sas writepipe.sas
• writepipe.sas Program:
libname test "mypipe";
data test.test_no (compress=no drop=text1-text44) ;
array text[44] $20 (/* list of 44 words or phrases */);
format longstring $200. ;
DO indexvariable=1 TO 20000000;
/* create a bunch of random values */
output test.test_no;
END;
run;
28
Named Pipes under UNIX – Filename Pipe with NOXCMD
• External Command Example – Read:
• UNIX/Linux commands:
mknod mypipe p /* not needed if created before)
gzip –-stdout input.gz > mypipe & /* runs in background/parallel */
sas readpipe.sas
• readpipe.sas Program:
libname test "mypipe";
data _null_;
set test.test_no;
retain total 0;
total=total+num1;
run;
29
UNIX X Command Tips and Tricks
The Author can be contacted at:
David B. Horvath, CCP
504 Longbotham Drive, Aston PA 19014-2502, USA
Phone: 1-610-859-8826
Email: dhorvath@cobs.com
Web: http://www.cobs.com/
LI: http://www.linkedin.com/in/dbhorvath
30
References 1
• x, sysexc, system
• https://v8doc.sas.com/sashtml/unixc/xcomm.htm
• http://support.sas.com/documentation/cdl/en/hostunx/63053/HTML/default/viewer.ht
m#p0w085btd5r0a4n1km4bcdpgqibt.htm
• %sysexec
• http://support.sas.com/documentation/cdl/en/mcrolref/62978/HTML/default/viewer.ht
m#n08ecabbpebv2xn13ieu8uylrohm.htm
• filename pipe
• http://support.sas.com/documentation/cdl/en/hostunx/63053/HTML/default/viewer.ht
m#n1ceb0xedanuj3n19l3g73awk1wf.htm
• https://documentation.sas.com/?docsetId=hostunx&docsetTarget=n1ceb0xedanuj3
n19l3g73awk1wf.htm&docsetVersion=9.4&locale=en
31
References 2
• bash scripts
• https://www.taniarascia.com/how-to-create-and-use-bash-scripts/
• systask:
• https://v8doc.sas.com/sashtml/unixc/z1215125.htm
• xsync
• https://v8doc.sas.com/sashtml/win/zp-xsync.htm
• xcmd
• http://support.sas.com/documentation/cdl/en/hostwin/69955/HTML/default/viewer.ht
m#p0xtd57b40ehdfn1jyk8yxemfrtv.htm
32
References 3
• x command (x windows) options
• https://v8doc.sas.com/sashtml/unixc/xcom.htm
• waitfor
• https://v8doc.sas.com/sashtml/unixc/z1215125.htm
33
Wrap Up (for Real)
Questions
and
Answers
?! ?!
?! ?!
?
? ?
?
!
!
!
!

Weitere ähnliche Inhalte

Was ist angesagt?

101 1.3 runlevels , shutdown, and reboot
101 1.3 runlevels , shutdown, and reboot101 1.3 runlevels , shutdown, and reboot
101 1.3 runlevels , shutdown, and rebootAcácio Oliveira
 
101 1.3 runlevels, shutdown, and reboot v2
101 1.3 runlevels, shutdown, and reboot v2101 1.3 runlevels, shutdown, and reboot v2
101 1.3 runlevels, shutdown, and reboot v2Acácio Oliveira
 
3.5 create, monitor and kill processes v2
3.5 create, monitor and kill processes v23.5 create, monitor and kill processes v2
3.5 create, monitor and kill processes v2Acácio Oliveira
 
Windows Debugging with WinDbg
Windows Debugging with WinDbgWindows Debugging with WinDbg
Windows Debugging with WinDbgArno Huetter
 
Basic MySQL Troubleshooting for Oracle Database Administrators
Basic MySQL Troubleshooting for Oracle Database AdministratorsBasic MySQL Troubleshooting for Oracle Database Administrators
Basic MySQL Troubleshooting for Oracle Database AdministratorsSveta Smirnova
 
Sebastián Guerrero - Ke ase Android? [Rooted CON 2013]
Sebastián Guerrero - Ke ase Android? [Rooted CON 2013]Sebastián Guerrero - Ke ase Android? [Rooted CON 2013]
Sebastián Guerrero - Ke ase Android? [Rooted CON 2013]RootedCON
 
CLUG 2010 09 - systemd - the new init system
CLUG 2010 09 - systemd - the new init systemCLUG 2010 09 - systemd - the new init system
CLUG 2010 09 - systemd - the new init systemPaulWay
 
My ppt @ bec doms on process management
My ppt @ bec doms on process managementMy ppt @ bec doms on process management
My ppt @ bec doms on process managementBabasab Patil
 
1.3 runlevels, shutdown, and reboot v3
1.3 runlevels, shutdown, and reboot v31.3 runlevels, shutdown, and reboot v3
1.3 runlevels, shutdown, and reboot v3Acácio Oliveira
 
Mod03 linking and accelerating
Mod03 linking and acceleratingMod03 linking and accelerating
Mod03 linking and acceleratingPeter Haase
 
IRQs: the Hard, the Soft, the Threaded and the Preemptible
IRQs: the Hard, the Soft, the Threaded and the PreemptibleIRQs: the Hard, the Soft, the Threaded and the Preemptible
IRQs: the Hard, the Soft, the Threaded and the PreemptibleAlison Chaiken
 
New features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in actionNew features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in actionSveta Smirnova
 
Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingPerformance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingSveta Smirnova
 
Troubleshooting MySQL Performance
Troubleshooting MySQL PerformanceTroubleshooting MySQL Performance
Troubleshooting MySQL PerformanceSveta Smirnova
 

Was ist angesagt? (20)

101 1.3 runlevels , shutdown, and reboot
101 1.3 runlevels , shutdown, and reboot101 1.3 runlevels , shutdown, and reboot
101 1.3 runlevels , shutdown, and reboot
 
101 1.3 runlevels, shutdown, and reboot v2
101 1.3 runlevels, shutdown, and reboot v2101 1.3 runlevels, shutdown, and reboot v2
101 1.3 runlevels, shutdown, and reboot v2
 
3.5 create, monitor and kill processes v2
3.5 create, monitor and kill processes v23.5 create, monitor and kill processes v2
3.5 create, monitor and kill processes v2
 
Windows Debugging with WinDbg
Windows Debugging with WinDbgWindows Debugging with WinDbg
Windows Debugging with WinDbg
 
Basic MySQL Troubleshooting for Oracle Database Administrators
Basic MySQL Troubleshooting for Oracle Database AdministratorsBasic MySQL Troubleshooting for Oracle Database Administrators
Basic MySQL Troubleshooting for Oracle Database Administrators
 
Systemd cheatsheet
Systemd cheatsheetSystemd cheatsheet
Systemd cheatsheet
 
Sebastián Guerrero - Ke ase Android? [Rooted CON 2013]
Sebastián Guerrero - Ke ase Android? [Rooted CON 2013]Sebastián Guerrero - Ke ase Android? [Rooted CON 2013]
Sebastián Guerrero - Ke ase Android? [Rooted CON 2013]
 
CLUG 2010 09 - systemd - the new init system
CLUG 2010 09 - systemd - the new init systemCLUG 2010 09 - systemd - the new init system
CLUG 2010 09 - systemd - the new init system
 
Linux monitoring
Linux monitoringLinux monitoring
Linux monitoring
 
My ppt @ bec doms on process management
My ppt @ bec doms on process managementMy ppt @ bec doms on process management
My ppt @ bec doms on process management
 
Process management
Process managementProcess management
Process management
 
1.3 runlevels, shutdown, and reboot v3
1.3 runlevels, shutdown, and reboot v31.3 runlevels, shutdown, and reboot v3
1.3 runlevels, shutdown, and reboot v3
 
OS_Ch2
OS_Ch2OS_Ch2
OS_Ch2
 
Mod03 linking and accelerating
Mod03 linking and acceleratingMod03 linking and accelerating
Mod03 linking and accelerating
 
Unix::Statgrab
Unix::StatgrabUnix::Statgrab
Unix::Statgrab
 
IRQs: the Hard, the Soft, the Threaded and the Preemptible
IRQs: the Hard, the Soft, the Threaded and the PreemptibleIRQs: the Hard, the Soft, the Threaded and the Preemptible
IRQs: the Hard, the Soft, the Threaded and the Preemptible
 
New features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in actionNew features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in action
 
Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingPerformance Schema for MySQL Troubleshooting
Performance Schema for MySQL Troubleshooting
 
Troubleshooting MySQL Performance
Troubleshooting MySQL PerformanceTroubleshooting MySQL Performance
Troubleshooting MySQL Performance
 
Rac introduction
Rac introductionRac introduction
Rac introduction
 

Ähnlich wie (SAS) UNIX X Command Tips and Tricks

202110 SESUG 49 UNIX X Command Tips and Tricks
202110 SESUG 49 UNIX X Command Tips and Tricks202110 SESUG 49 UNIX X Command Tips and Tricks
202110 SESUG 49 UNIX X Command Tips and Tricksdhorvath
 
202202 SUGUKI UNIX X Command Tips and Tricks
202202 SUGUKI UNIX X Command Tips and Tricks202202 SUGUKI UNIX X Command Tips and Tricks
202202 SUGUKI UNIX X Command Tips and Tricksdhorvath
 
Linux kernel debugging
Linux kernel debuggingLinux kernel debugging
Linux kernel debuggingHao-Ran Liu
 
A Reimplementation of NetBSD Based on a Microkernel by Andrew S. Tanenbaum
A Reimplementation of NetBSD Based on a Microkernel by Andrew S. TanenbaumA Reimplementation of NetBSD Based on a Microkernel by Andrew S. Tanenbaum
A Reimplementation of NetBSD Based on a Microkernel by Andrew S. Tanenbaumeurobsdcon
 
Auditing the Opensource Kernels
Auditing the Opensource KernelsAuditing the Opensource Kernels
Auditing the Opensource KernelsSilvio Cesare
 
Week1 Electronic System-level ESL Design and SystemC Begin
Week1 Electronic System-level ESL Design and SystemC BeginWeek1 Electronic System-level ESL Design and SystemC Begin
Week1 Electronic System-level ESL Design and SystemC Begin敬倫 林
 
Part 04 Creating a System Call in Linux
Part 04 Creating a System Call in LinuxPart 04 Creating a System Call in Linux
Part 04 Creating a System Call in LinuxTushar B Kute
 
Chapter 1: Introduction to Command Line
Chapter 1: Introduction to  Command LineChapter 1: Introduction to  Command Line
Chapter 1: Introduction to Command Lineazzamhadeel89
 
Summit demystifying systemd1
Summit demystifying systemd1Summit demystifying systemd1
Summit demystifying systemd1Susant Sahani
 
Chapter 1: Introduction to Command Line
Chapter 1: Introduction  to Command LineChapter 1: Introduction  to Command Line
Chapter 1: Introduction to Command Lineazzamhadeel89
 
ARM® Cortex™ M Bootup_CMSIS_Part_2_3
ARM® Cortex™ M Bootup_CMSIS_Part_2_3ARM® Cortex™ M Bootup_CMSIS_Part_2_3
ARM® Cortex™ M Bootup_CMSIS_Part_2_3Raahul Raghavan
 
Linux or unix interview questions
Linux or unix interview questionsLinux or unix interview questions
Linux or unix interview questionsTeja Bheemanapally
 
ppt aman solanki.pptx
ppt aman solanki.pptxppt aman solanki.pptx
ppt aman solanki.pptxHUNNTERRAJPUT
 

Ähnlich wie (SAS) UNIX X Command Tips and Tricks (20)

202110 SESUG 49 UNIX X Command Tips and Tricks
202110 SESUG 49 UNIX X Command Tips and Tricks202110 SESUG 49 UNIX X Command Tips and Tricks
202110 SESUG 49 UNIX X Command Tips and Tricks
 
202202 SUGUKI UNIX X Command Tips and Tricks
202202 SUGUKI UNIX X Command Tips and Tricks202202 SUGUKI UNIX X Command Tips and Tricks
202202 SUGUKI UNIX X Command Tips and Tricks
 
Linux kernel debugging
Linux kernel debuggingLinux kernel debugging
Linux kernel debugging
 
A Reimplementation of NetBSD Based on a Microkernel by Andrew S. Tanenbaum
A Reimplementation of NetBSD Based on a Microkernel by Andrew S. TanenbaumA Reimplementation of NetBSD Based on a Microkernel by Andrew S. Tanenbaum
A Reimplementation of NetBSD Based on a Microkernel by Andrew S. Tanenbaum
 
Auditing the Opensource Kernels
Auditing the Opensource KernelsAuditing the Opensource Kernels
Auditing the Opensource Kernels
 
Week1 Electronic System-level ESL Design and SystemC Begin
Week1 Electronic System-level ESL Design and SystemC BeginWeek1 Electronic System-level ESL Design and SystemC Begin
Week1 Electronic System-level ESL Design and SystemC Begin
 
Part 04 Creating a System Call in Linux
Part 04 Creating a System Call in LinuxPart 04 Creating a System Call in Linux
Part 04 Creating a System Call in Linux
 
Hotsos Advanced Linux Tools
Hotsos Advanced Linux ToolsHotsos Advanced Linux Tools
Hotsos Advanced Linux Tools
 
OS_lab_file.pdf
OS_lab_file.pdfOS_lab_file.pdf
OS_lab_file.pdf
 
linux installation.pdf
linux installation.pdflinux installation.pdf
linux installation.pdf
 
Chapter 1: Introduction to Command Line
Chapter 1: Introduction to  Command LineChapter 1: Introduction to  Command Line
Chapter 1: Introduction to Command Line
 
Summit demystifying systemd1
Summit demystifying systemd1Summit demystifying systemd1
Summit demystifying systemd1
 
Chapter 1: Introduction to Command Line
Chapter 1: Introduction  to Command LineChapter 1: Introduction  to Command Line
Chapter 1: Introduction to Command Line
 
ARM® Cortex™ M Bootup_CMSIS_Part_2_3
ARM® Cortex™ M Bootup_CMSIS_Part_2_3ARM® Cortex™ M Bootup_CMSIS_Part_2_3
ARM® Cortex™ M Bootup_CMSIS_Part_2_3
 
Linux or unix interview questions
Linux or unix interview questionsLinux or unix interview questions
Linux or unix interview questions
 
ppt aman solanki.pptx
ppt aman solanki.pptxppt aman solanki.pptx
ppt aman solanki.pptx
 
UNIX Basics and Cluster Computing
UNIX Basics and Cluster ComputingUNIX Basics and Cluster Computing
UNIX Basics and Cluster Computing
 
2004 ugm-tips-tricks
2004 ugm-tips-tricks2004 ugm-tips-tricks
2004 ugm-tips-tricks
 
Ch04 system administration
Ch04 system administration Ch04 system administration
Ch04 system administration
 
Ch04
Ch04Ch04
Ch04
 

Mehr von David Horvath

20190413 zen and the art of programming
20190413 zen and the art of programming20190413 zen and the art of programming
20190413 zen and the art of programmingDavid Horvath
 
20180414 nevil shute no highway modern metal fatigue
20180414 nevil shute no highway modern metal fatigue20180414 nevil shute no highway modern metal fatigue
20180414 nevil shute no highway modern metal fatigueDavid Horvath
 
20180410 sasgf2018 2454 lazy programmers xml ppt
20180410 sasgf2018 2454 lazy programmers xml ppt20180410 sasgf2018 2454 lazy programmers xml ppt
20180410 sasgf2018 2454 lazy programmers xml pptDavid Horvath
 
20180324 leveraging unix tools
20180324 leveraging unix tools20180324 leveraging unix tools
20180324 leveraging unix toolsDavid Horvath
 
20180324 zen and the art of programming
20180324 zen and the art of programming20180324 zen and the art of programming
20180324 zen and the art of programmingDavid Horvath
 
20171106 sesug bb 184 zen and the art of problem solving
20171106 sesug bb 184 zen and the art of problem solving20171106 sesug bb 184 zen and the art of problem solving
20171106 sesug bb 184 zen and the art of problem solvingDavid Horvath
 
20171106 sesug bb 180 proc import ppt
20171106 sesug bb 180 proc import ppt20171106 sesug bb 180 proc import ppt
20171106 sesug bb 180 proc import pptDavid Horvath
 
20150904 "A Few Words About 'In The Wet' by Nevil Shute"
20150904 "A Few Words About 'In The Wet' by Nevil Shute"20150904 "A Few Words About 'In The Wet' by Nevil Shute"
20150904 "A Few Words About 'In The Wet' by Nevil Shute"David Horvath
 
20120606 Lazy Programmers Write Self-Modifying Code /or/ Dealing with XML Ord...
20120606 Lazy Programmers Write Self-Modifying Code /or/ Dealing with XML Ord...20120606 Lazy Programmers Write Self-Modifying Code /or/ Dealing with XML Ord...
20120606 Lazy Programmers Write Self-Modifying Code /or/ Dealing with XML Ord...David Horvath
 
20150312 NOBS for Noobs
20150312 NOBS for Noobs20150312 NOBS for Noobs
20150312 NOBS for NoobsDavid Horvath
 
20140612 phila sug proc import
20140612 phila sug proc import20140612 phila sug proc import
20140612 phila sug proc importDavid Horvath
 
20170419 To COMPRESS or Not, to COMPRESS or ZIP
20170419 To COMPRESS or Not, to COMPRESS or ZIP20170419 To COMPRESS or Not, to COMPRESS or ZIP
20170419 To COMPRESS or Not, to COMPRESS or ZIPDavid Horvath
 

Mehr von David Horvath (12)

20190413 zen and the art of programming
20190413 zen and the art of programming20190413 zen and the art of programming
20190413 zen and the art of programming
 
20180414 nevil shute no highway modern metal fatigue
20180414 nevil shute no highway modern metal fatigue20180414 nevil shute no highway modern metal fatigue
20180414 nevil shute no highway modern metal fatigue
 
20180410 sasgf2018 2454 lazy programmers xml ppt
20180410 sasgf2018 2454 lazy programmers xml ppt20180410 sasgf2018 2454 lazy programmers xml ppt
20180410 sasgf2018 2454 lazy programmers xml ppt
 
20180324 leveraging unix tools
20180324 leveraging unix tools20180324 leveraging unix tools
20180324 leveraging unix tools
 
20180324 zen and the art of programming
20180324 zen and the art of programming20180324 zen and the art of programming
20180324 zen and the art of programming
 
20171106 sesug bb 184 zen and the art of problem solving
20171106 sesug bb 184 zen and the art of problem solving20171106 sesug bb 184 zen and the art of problem solving
20171106 sesug bb 184 zen and the art of problem solving
 
20171106 sesug bb 180 proc import ppt
20171106 sesug bb 180 proc import ppt20171106 sesug bb 180 proc import ppt
20171106 sesug bb 180 proc import ppt
 
20150904 "A Few Words About 'In The Wet' by Nevil Shute"
20150904 "A Few Words About 'In The Wet' by Nevil Shute"20150904 "A Few Words About 'In The Wet' by Nevil Shute"
20150904 "A Few Words About 'In The Wet' by Nevil Shute"
 
20120606 Lazy Programmers Write Self-Modifying Code /or/ Dealing with XML Ord...
20120606 Lazy Programmers Write Self-Modifying Code /or/ Dealing with XML Ord...20120606 Lazy Programmers Write Self-Modifying Code /or/ Dealing with XML Ord...
20120606 Lazy Programmers Write Self-Modifying Code /or/ Dealing with XML Ord...
 
20150312 NOBS for Noobs
20150312 NOBS for Noobs20150312 NOBS for Noobs
20150312 NOBS for Noobs
 
20140612 phila sug proc import
20140612 phila sug proc import20140612 phila sug proc import
20140612 phila sug proc import
 
20170419 To COMPRESS or Not, to COMPRESS or ZIP
20170419 To COMPRESS or Not, to COMPRESS or ZIP20170419 To COMPRESS or Not, to COMPRESS or ZIP
20170419 To COMPRESS or Not, to COMPRESS or ZIP
 

Kürzlich hochgeladen

How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 

Kürzlich hochgeladen (20)

How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 

(SAS) UNIX X Command Tips and Tricks

  • 1. UNIX X Command Tips and Tricks David B. Horvath, CCP, MS PhilaSUG Winter 2019 TD Bank, Wilmington DE March 19, 2019
  • 2. 2 UNIX X Command Tips and Tricks The Author can be contacted at: 504 Longbotham Drive, Aston PA 19014-2502, USA Phone: 1-610-859-8826 Email: dhorvath@cobs.com Web: http://www.cobs.com/ All trademarks and servicemarks are the property of their respective owners. Copyright © 2019 David B. Horvath, CCP — All Rights Reserved
  • 3. Abstract SAS provides the ability to execute operating system level commands from within your SAS code – generically known as the “X Command”. This session explores the various commands, the advantages and disadvantages of each, and their alternatives. The focus is on UNIX/Linux but much of the same applies to Windows as well. Under SAS EG, any issued commands execute on the SAS engine, not necessarily on the PC. • X • %sysexec • Call system • Systask command • Filename pipe • &SYSRC • Waitfor Alternatives will also be addressed – how to handle when NOXCMD is the default for your installation, saving results, and error checking. 3
  • 4. 4 My Background • David is an IT Professional who has worked with various platforms since the 1980’s with a variety of development and analysis tools. • He has presented at PhilaSUG, SESUG, and SGF previously and has presented workshops and seminars in Australia, France, the US, Canada, and Oxford England (about the British Author Nevil Shute) for various organizations. • He holds an undergraduate degree in Computer and Information Sciences from Temple University and a Masters in Organizational Dynamics from UPENN. He achieved the Certified Computing Professional designation with honors. • Most of his career has been in consulting (although recently he has been in-house) in the Philadelphia PA area. He is currently in Data Analytics "Engineering" at a Regional Bank. • He has several books to his credit (none SAS related) and is an Adjunct Instructor covering IT topics for University of Phoenix.
  • 5. 5 Options • Execution of any System command from within your SAS program is dependent on one option's setting: XCMD Enables the X command in SAS. • Which can only be set at startup: options xcmd; ____ 30 WARNING 30-12: SAS option XCMD is valid only at startup of the SAS System. The SAS option is ignored. • If NOXCMD is set, you're out of luck. Sorry! • University Edition is NOXCMD
  • 6. 6 X • The basic X Command • Runs independent of data steps and macros • The SAS Engine will interpret some commands • Does not spawn off sub-process • This fact is important because information does not persist between sub- processes • Handling within the log is annoying
  • 7. 7 X • X Command Examples: • pwd and cd under UNIX: NOTE: Current working directory is '/this/is/the/sas/install/directory'. 26 x "pwd" ; /* works within SAS */ 27 x "cd /my/directory/is/here" 27 ! ; /* works within SAS */ NOTE: Current working directory is '/my/directory/is/here'. 28 x "pwd" ; /* works within SAS */ • echo and combined commands under UNIX: 29 x "echo $HOME" 29 ! ; /* works but no output */ 30 x "pwd; cd $HOME; pwd" 30 ! ; /* no output, works? */
  • 8. 8 X • X Command Examples: • We can combine commands on one line under UNIX: 31 x 'echo start; echo mid; echo end>temp2.txt' 31 ! ; /* output to file, works */ • > sends STDOUT to a file • I know this works because I can look at the output file (temp2.txt): end • Why didn't "start" and "mid" appear? • Because of the way I wrote the statement!
  • 9. 9 X • X Command Examples: • We can combine commands on one line under UNIX: 37 x '(echo start; echo mid; echo end)>temp1.txt' 37 ! /* output to file, all 3 statements to file */ • I know this works because I can look at the output file (temp1.txt): start mid end • The difference is the parenthesis which combines the output in UNIX • Because of the way I wrote the statement!
  • 10. 10 X and %SYSRC • How do I know a command worked? • %SYSRC will tell me – returns the UNIX error code 37 x '(echo start; echo mid; echo end)>temp1.txt' 37 ! ; /* output to file, all 3 statements to file */ SYMBOLGEN: Macro variable SYSRC resolves to 0 38 %put &SYSRC; 0 • Zero is success in UNIX • If the command does not exist, we get 127: 39 x 'this_command_doesnot_exist' 39 ! ; /* non-zero RC */ SYMBOLGEN: Macro variable SYSRC resolves to 127 40 %put &SYSRC; 127
  • 11. 11 X and %SYSRC • How do I know a command worked? • If the command does not exist, we get 127: 41 x 'this_command_doesnot_exist 2>test5.txt' 41 ! ; /* non-zero RC */ SYMBOLGEN: Macro variable SYSRC resolves to 127 42 %put &SYSRC; 127 • And we can save error output (2> sends STDERR to a file): /bin/bash: this_command_doesnot_exist: command not found 43 x 'ls -al no_such_file' 43 ! ; /* non-zero RC */ SYMBOLGEN: Macro variable SYSRC resolves to 2 44 %put &SYSRC; 2
  • 12. 12 X and %SYSRC • How do I know a command worked? • The command itself may return an error as well: 43 x 'ls -al no_such_file' 43 ! ; /* non-zero RC */ SYMBOLGEN: Macro variable SYSRC resolves to 2 44 %put &SYSRC; 2 • In this case, "no_such_file" does not exist • 'man ls' executed at the command line will provide this information Exit status: 0 if OK, 1 if minor problems (e.g., cannot access subdirectory), 2 if serious trouble (e.g., cannot access command-line argument).
  • 13. 13 %sysexec – Macros • We can execute system commands within a macro: 72 %macro commands; 73 %sysexec %str(ls -al > test6.txt); 74 %put &SYSRC; 75 %sysexec %str(command_doesnot_exist 2> test7.txt); 76 %put &SYSRC; 77 %mend commands; 78 79 %commands; • Note the use of %SYSRC
  • 14. 14 %sysexec – Macros • And get the following results: 79 %commands; MLOGIC(COMMANDS): Beginning execution. MLOGIC(COMMANDS): %SYSEXEC ls al test6.txt MLOGIC(COMMANDS): %PUT &SYSRC SYMBOLGEN: Macro variable SYSRC resolves to 0 0 MLOGIC(COMMANDS): %SYSEXEC command_doesnot_exist 2 test7.txt MLOGIC(COMMANDS): %PUT &SYSRC SYMBOLGEN: Macro variable SYSRC resolves to 127 127 MLOGIC(COMMANDS): Ending execution.
  • 15. 15 Call System – Data Step • Use Call System within a data step: 85 data dir; 86 filename commands PIPE "ls | head -2"; 87 infile commands truncover; 88 input result $char60.; 89 90 string="echo " || result || " >> test4.txt"; 91 call system(string); /* no output - but it executes multiple times */ 92 system_rc=symget("SYSRC"); 93 call system("this_command_doesnot_exist"); 94 system_rc2=symget("SYSRC"); 95 96 systask command "pwd" wait shell; /* runs once */ NOTE: LOG/Output from task "task59" > /my/directory/is/here NOTE: End of LOG/Output from task "task59" 97 output; 98 run;
  • 16. 16 Call System – Data Step • Call System results: NOTE: The infile COMMANDS is: Pipe command="ls | head -2" NOTE: 2 records were read from the infile COMMANDS. The minimum record length was 22. The maximum record length was 24. NOTE: The data set WORK.DIR has 2 observations and 4 variables. NOTE: Compressing data set WORK.DIR increased size by 100.00 percent. Compressed is 2 pages; un-compressed would require 1 pages. NOTE: DATA statement used (Total process time): real time 0.02 seconds cpu time 0.00 seconds
  • 17. 17 Call System – Data Step • Call System output: • Results: • Test4.txt: FILE1 FILE2 • Two records were read from infile • Two records were written to work.dir • Two records were written to test4.txt via the echo command • SAS Engine does not interpret these commands Obsresult string system_rc system_rc2 1FILE1 echo FILE1 >> test4.txt 0 127 2FILE2 echo FILE2 >> test4.txt 0 127
  • 18. 18 'Systask command' • 'Systask command' operates two modes: • With "shell" modifier, SAS does not interpret the commands • Without "shell", it behaves like X • &SYSRC is set 54 systask command 'echo BOL $HOME EOL' wait; NOTE: LOG/Output from task "task62" > BOL $HOME EOL NOTE: End of LOG/Output from task "task62" 54 ! /* $HOME not interpreted */ 55 systask command "echo BOL $HOME EOL" wait shell; NOTE: LOG/Output from task "task63" > BOL /my/directory/is/here EOL NOTE: End of LOG/Output from task "task63" 55 ! /* $HOME interpreted */
  • 19. 19 'Systask command' and 'Systask list' • Other Options: • Wait: wait for this command to execute before starting next • Cleanup: wait for this command and any nowait before starting next • Shell: Can also specify the shell to use: shell="/usr/bin/ksh" • Status: Can specify a status variable to check later (rather than &SYSRC) • Taskname: Can specify task name for later use in Waitfor • Systask list will provide status of any nowait systasks "task150" -------------- Type: Task State: COMPLETE Status Macro Variable: Unspecified 73 74 systask list;
  • 20. 20 'Systask command' and 'Waitfor' • The waitfor command is used to wait for systask command nowait to complete • Can wait for _ANY_ of listed tasknames to complete (default) • Can wait for _ALL_ of listed tasknames to complete • Can specify length of time to wait: Timeout=number-of-seconds • General form is waitfor _ALL_ task1 task2 task3;
  • 21. 21 Filename pipe • Acts like normal filename statement • Accepts data written from SAS (File/Put) • Provides data for SAS to read (Infile/Input) • Allows for execution of UNIX command • Is more efficient than running command separately (parallelization) • Handy when you have version limitations: filename gzipit zip '/my/output/directory/file.txt.gz' gzip; * requires 9.4M5; filename gzipit pipe 'gzip -c > /my/output/directory/file.txt.gz'; * run the UNIX gzip;
  • 22. 22 Filename Pipe – Earlier Code Example • UNIX Commands are Executed prior to input statement: 85 data dir; 86 filename commands PIPE "ls | head -2"; 87 infile commands truncover; 88 input result $char60.; 89 90 string="echo " || result || " >> test4.txt"; 91 call system(string); /* no output - but it executes multiple times */ 92 system_rc=symget("SYSRC"); 93 call system("this_command_doesnot_exist"); 94 system_rc2=symget("SYSRC"); 95 96 systask command "pwd" wait shell; /* runs once */ NOTE: LOG/Output from task "task59" > /my/directory/is/here NOTE: End of LOG/Output from task "task59" 97 output; 98 run;
  • 23. 23 Filename Pipe • Unfortunately, &SYSRC is not set by Filename Pipe: 113 data baddir; 114 filename commands PIPE "lx ; lx ; lx"; 115 system_rc=symget("SYSRC"); 116 117 infile commands truncover; 118 input result $char60.; 119 output; 120 run; NOTE: The infile COMMANDS is: Pipe command="lx ; lx ; lx" NOTE: 3 records were read from the infile COMMANDS. The minimum record length was 32. The maximum record length was 32.
  • 24. 24 Shell Scripts • When NOXCMD is set, none of these will work. • You can move the commands into a shell script: #!/bin/ksh cd /desired/directory # You can check return codes here with the $? if [[ $? -gt 0 ]]; then echo "cd failed" exit 3 fi # if we get here 'cd' succeeded ls –al | head -2 > temp.txt sas your_sas_part_1.sas pwd sas your_sas_part_2.sas gzip /my/output/directory/file.txt
  • 25. 25 Final Thoughts • It is all about choices • Sometimes it is better to execute UNIX commands in your program • Sometimes not
  • 27. 27 Named Pipes under UNIX – Filename Pipe with NOXCMD • I can use UNIX “Named Pipes” with files • Datasets make use of the "Sequential Data Engine" ("TAPE" engine) • External Command Example – Write: • UNIX/Linux commands: mknod mypipe p gzip –c mypipe > input.gz & /* runs in background */ sas writepipe.sas • writepipe.sas Program: libname test "mypipe"; data test.test_no (compress=no drop=text1-text44) ; array text[44] $20 (/* list of 44 words or phrases */); format longstring $200. ; DO indexvariable=1 TO 20000000; /* create a bunch of random values */ output test.test_no; END; run;
  • 28. 28 Named Pipes under UNIX – Filename Pipe with NOXCMD • External Command Example – Read: • UNIX/Linux commands: mknod mypipe p /* not needed if created before) gzip –-stdout input.gz > mypipe & /* runs in background/parallel */ sas readpipe.sas • readpipe.sas Program: libname test "mypipe"; data _null_; set test.test_no; retain total 0; total=total+num1; run;
  • 29. 29 UNIX X Command Tips and Tricks The Author can be contacted at: David B. Horvath, CCP 504 Longbotham Drive, Aston PA 19014-2502, USA Phone: 1-610-859-8826 Email: dhorvath@cobs.com Web: http://www.cobs.com/ LI: http://www.linkedin.com/in/dbhorvath
  • 30. 30 References 1 • x, sysexc, system • https://v8doc.sas.com/sashtml/unixc/xcomm.htm • http://support.sas.com/documentation/cdl/en/hostunx/63053/HTML/default/viewer.ht m#p0w085btd5r0a4n1km4bcdpgqibt.htm • %sysexec • http://support.sas.com/documentation/cdl/en/mcrolref/62978/HTML/default/viewer.ht m#n08ecabbpebv2xn13ieu8uylrohm.htm • filename pipe • http://support.sas.com/documentation/cdl/en/hostunx/63053/HTML/default/viewer.ht m#n1ceb0xedanuj3n19l3g73awk1wf.htm • https://documentation.sas.com/?docsetId=hostunx&docsetTarget=n1ceb0xedanuj3 n19l3g73awk1wf.htm&docsetVersion=9.4&locale=en
  • 31. 31 References 2 • bash scripts • https://www.taniarascia.com/how-to-create-and-use-bash-scripts/ • systask: • https://v8doc.sas.com/sashtml/unixc/z1215125.htm • xsync • https://v8doc.sas.com/sashtml/win/zp-xsync.htm • xcmd • http://support.sas.com/documentation/cdl/en/hostwin/69955/HTML/default/viewer.ht m#p0xtd57b40ehdfn1jyk8yxemfrtv.htm
  • 32. 32 References 3 • x command (x windows) options • https://v8doc.sas.com/sashtml/unixc/xcom.htm • waitfor • https://v8doc.sas.com/sashtml/unixc/z1215125.htm
  • 33. 33 Wrap Up (for Real) Questions and Answers ?! ?! ?! ?! ? ? ? ? ! ! ! !