BookmarkSubscribeRSS Feed
sasprofile
Quartz | Level 8

Hello everyone How can I create run time directory on SAS unix server and other OS specific commands ls, pwd...etc via SAS Enterprise guide using X command. I did X commands in SAS sessions from EG to run some OS specific commands such as mkdir,ls,pwd...but it looks like they are not working. below is the one of the x command I tried

 

x ls -l;

 

12NODS tagsets.sasreport13(ID=EGSR) FILE=EGSR

13 STYLE=HtmlBlue

14 STYLESHEET=(URL="file:///C:/Program%20Files%20(x86)/SASHome94/x86/SASEnterpriseGuide/7.1/Styles/HtmlBlue.css")

15 NOGTITLE

16 NOGFOOTNOTE

17 GPATH=&sasworklocation

18 ENCODING=UTF8

19 options(rolap="on")

20 ; NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR

21

22 GOPTIONS ACCESSIBLE;

23 x ls -l 23 ! ; 

24

25 GOPTIONS NOACCESSIBLE;

26 %LET _CLIENTTASKLABEL=;

27 %LET _CLIENTPROJECTPATH=;

28 %LET _CLIENTPROJECTNAME=;

29 %LET _SASPROGRAMFILE=;

30

31 ;*';*";*/;quit;run;

32 ODS _ALL_ CLOSE;

33

 

 

This is our new SAS 9.4 Environment,so am not sure How this commands will work from SAS EG,do I need to enable something somewhere in the Tools or may be am using the commands wrongly. I would really appreciate if someone can help me on this Thank you in Advance

14 REPLIES 14
RahulG
Barite | Level 11

To be very specific how to create directory 

 

I use following statement. Option dlcreatedir helps to create new directory if it is not present. 

 

options dlcreatedir;

libname temp "C:\users\New_folder";

libname temp;

 

 

 

Reeza
Super User

Do you have administration privileges for your SAS installation? 

 

You do need to enable X command in EG as its turned off by default. 

 

To create a folder you can use DCREATE 

Kurt_Bremser
Super User

a) you need XCMD enabled on the workspace server; run proc options, and then look for XCMD in the log

b) to reliably catch the output of system commands, do this:

filename oscmd pipe "ls -l 2>&1";
data _null_;
infile oscmd;
input;
put _infile_;
run;
filename oscmd clear;

The 2>&1 reroutes stderr to stdout, so all output, including error messages, will be streamed to SAS. The data step then writes all output (if present) to the SAS log.

 

FelipeSch
Calcite | Level 5
I tried to run the example, but my code remains running and does not generate any results.

I need run a .sh file from UNIX. The .sh file contains a code to download an online file. Can you help me?
Kurt_Bremser
Super User

Please open a new thread with your question. Hijacking old threads is not useful, as you can see from the lack of any answers to your questions; old threads are near invisible to the crowd here.

Please include there:

the SAS code you run (use the "little running man" for this)

the shell script code (use the </> button)

the log from the SAS code, if available (also use the </> button)

 

Kurt_Bremser
Super User

Addendum: When posting code, use the little "running man" icon to get a subwindow for entering code. Code will then be displayed in fixed-width font and with syntax highlighting similar to the SAS Enhanced Editor.

For log output or data, use the {i} icon. Fixed-width font, but no syntax highlighting.

This makes it much easier for others to read your posts.

sasprofile
Quartz | Level 8
Thank you for all your prompt replies, I truly appreciate that I have checked in the Work space Server that Allow XCMD checkbox is checked in the Workspaceserver properties. but still the X commands in EG is not working, basically I want to run few basic commands like mkdir, ls, pwd from EG please help
Reeza
Super User

There's nothing in your log to indicate it didn't work. You called the command but did nothing with results. 

 

Whoch is much easier to see once I formatted your code. 

 

Try A mkdir command to test it. 

 

And review how to obtain results from ls. 

 

 

sasprofile
Quartz | Level 8

Reeza thanks for your reply 

 

This is how the command looks for mkdir right if am not wrong 

 

X 'mkdir abc'

 

Kurt_Bremser
Super User

@sasprofile wrote:

Reeza thanks for your reply 

 

This is how the command looks for mkdir right if am not wrong 

 

X 'mkdir abc'

 


Be aware that you specify a relative path (not starting at the UNIX root directory). This means that SAS will try to create the directory at the current working directory (CWD) of the SAS workspace server process.

With the SAS default installation, this is most probably the /sasconfig/Lev1/SASApp/WorkspaceServer directory, where you won't want to create a new directory, and where you most probably are not allowed to create anything.

 

Try

filename oscmd pipe "mkdir $HOME/abc 2>&1";
data _null_;
infile oscmd;
input;
put _infile_;
run;
filename oscmd clear;

instead and look at the log.

sasprofile
Quartz | Level 8

KurtBremser

 

Thanks once again for your prompt replies, I really appreciate that

here is the log files for the two codes you sent,for the first code the directory created in the home directory

and the second code it listed some files...so it means the X command in EG is not working.

but why when am issuing the below commands its not working

 

 x 'ls -l;

 

x 'pwd'; 

 

x  'cd /home/xu84178';

 

x 'ls -l  >  ls.txt  ' ;

 

 

 

filename oscmd pipe "mkdir $HOME/abc 2>&1";
data _null_;
infile oscmd;
input;
put _infile_;
run;
filename oscmd clear;


1
1 ;*';*";*/;quit;run;
2 OPTIONS PAGENO=MIN;
3 %LET _CLIENTTASKLABEL='Program';
4 %LET _CLIENTPROJECTPATH='';
5 %LET _CLIENTPROJECTNAME='';
6 %LET _SASPROGRAMFILE=;
7
8 ODS _ALL_ CLOSE;
9 OPTIONS DEV=ACTIVEX;
10 GOPTIONS XPIXELS=0 YPIXELS=0;
11 FILENAME EGSR TEMP;
12 ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR
13 STYLE=HtmlBlue
14 STYLESHEET=(URL="file:///C:/Program%20Files%20(x86)/SASHome/x86/SASEnterpriseGuide/7.1/Styles/HtmlBlue.css")
15 NOGTITLE
16 NOGFOOTNOTE
17 GPATH=&sasworklocation
18 ENCODING=UTF8
19 options(rolap="on")
20 ;
NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
21
22 GOPTIONS ACCESSIBLE;
23 filename oscmd pipe "mkdir /home/gx25664/abc 2>&1";
24 data _null_;
25 infile oscmd;
26 input;
27 put _infile_;
28 run;

NOTE: The infile OSCMD is:
Pipe command="mkdir /home/gx25664/abc 2>&1"

NOTE: 0 records were read from the infile OSCMD.
NOTE: PROCEDURE| _DISARM| STOP| _DISARM| 2016-08-01T23:31:01,926-07:00| _DISARM| WorkspaceServer| _DISARM| SAS| _DISARM| |
_DISARM| 19038208| _DISARM| 19038208| _DISARM| 11| _DISARM| 11| _DISARM| 0| _DISARM| 824| _DISARM| 0.010000| _DISARM|
0.022196| _DISARM| 1785738661.904777| _DISARM| 1785738661.926973| _DISARM| 0.010000| _DISARM| | _ENDDISARM
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
user cpu time 0.01 seconds
system cpu time 0.00 seconds
memory 765.28k
OS Memory 18592.00k
Timestamp 08/01/2016 11:31:01 PM
Step Count 4 Switch Count 49
Page Faults 0
Page Reclaims 362
Page Swaps 0
Voluntary Context Switches 155
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 0


29 filename oscmd clear;
NOTE: Fileref OSCMD has been deassigned.
30
31 GOPTIONS NOACCESSIBLE;


32 %LET _CLIENTTASKLABEL=;
33 %LET _CLIENTPROJECTPATH=;
34 %LET _CLIENTPROJECTNAME=;
35 %LET _SASPROGRAMFILE=;
36
37 ;*';*";*/;quit;run;
38 ODS _ALL_ CLOSE;
39
40
41 QUIT; RUN;
42
 

 

 

filename oscmd pipe "ls -l 2>&1";
data _null_;
infile oscmd;
input;
put _infile_;
run;
filename oscmd clear;





1 ;*';*";*/;quit;run;
2 OPTIONS PAGENO=MIN;
3 %LET _CLIENTTASKLABEL='Program (2)';
4 %LET _CLIENTPROJECTPATH='';
5 %LET _CLIENTPROJECTNAME='';
6 %LET _SASPROGRAMFILE=;
7
8 ODS _ALL_ CLOSE;
9 OPTIONS DEV=ACTIVEX;
10 GOPTIONS XPIXELS=0 YPIXELS=0;
11 FILENAME EGSR TEMP;
12 ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR
13 STYLE=HtmlBlue
14 STYLESHEET=(URL="file:///C:/Program%20Files%20(x86)/SASHome/x86/SASEnterpriseGuide/7.1/Styles/HtmlBlue.css")
15 NOGTITLE
16 NOGFOOTNOTE
17 GPATH=&sasworklocation
18 ENCODING=UTF8
19 options(rolap="on")
20 ;
NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
21
22 GOPTIONS ACCESSIBLE;
23 filename oscmd pipe "ls -l 2>&1";
24 data _null_;
25 infile oscmd;
26 input;
27 put _infile_;
28 run;

NOTE: The infile OSCMD is:
Pipe command="ls -l 2>&1"

total 68
-rw-r--r-- 1 sas sas 343 Jul 29 14:02 appserver_autoexec.sas
-rw-r--r-- 1 sas sas 365 Jul 29 18:25 appserver_autoexec_usermods.sas
-rw-r--r-- 1 sas sas 236 Jul 29 14:02 appserver_autoexec_usermods.sas_20160729_182516
-rw-r--r-- 1 sas sas 437 Jul 29 14:02 appservercontext_env.sh
-rwxr-xr-x 1 sas sas 203 Jul 29 14:02 appservercontext_env_usermods.sh
drwxr-xr-x 4 sas sas 4096 Jul 29 18:25 BatchServer
drwxr-xr-x 3 sas sas 4096 Jul 29 18:25 ConnectServer
drwxr-xr-x 2 sas sas 4096 Jul 29 14:02 Data
drwxr-x--- 5 sas sas 4096 Jul 29 18:25 PooledWorkspaceServer
drwxr-xr-x 5 sas sas 4096 Jul 29 14:02 SASEnvironment
-rwxr-xr-x 1 sas sas 894 Jul 29 14:02 sas.sh
-rwxr-xr-x 1 sas sas 165 Jul 29 14:02 sas_usermods.sh
-rw-r--r-- 1 sas sas 1141 Jul 29 14:02 sasv9.cfg
-rw-r--r-- 1 sas sas 295 Jul 29 14:02 sasv9_usermods.cfg
drwxr-x--- 5 sas sas 4096 Jul 29 18:25 StoredProcessServer
drwxrwxr-x 2 sas sas 4096 Aug 1 18:15 test
drwxr-xr-x 4 sas sas 4096 Jul 29 18:25 WorkspaceServer
NOTE: 18 records were read from the infile OSCMD.
The minimum record length was 8.
The maximum record length was 86.
NOTE: PROCEDURE| _DISARM| STOP| _DISARM| 2016-08-01T23:39:15,542-07:00| _DISARM| WorkspaceServer| _DISARM| SAS| _DISARM| |
_DISARM| 20877312| _DISARM| 19300352| _DISARM| 11| _DISARM| 11| _DISARM| 8| _DISARM| 872| _DISARM| 0.020000| _DISARM|
0.025575| _DISARM| 1785739155.516796| _DISARM| 1785739155.542371| _DISARM| 0.010000| _DISARM| | _ENDDISARM
NOTE: DATA statement used (Total process time):
2 The SAS System

real time 0.02 seconds
user cpu time 0.01 seconds
system cpu time 0.01 seconds
memory 764.15k
OS Memory 18848.00k
Timestamp 08/01/2016 11:39:15 PM
Step Count 6 Switch Count 92
Page Faults 0
Page Reclaims 308
Page Swaps 0
Voluntary Context Switches 335
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 0


29 filename oscmd clear;
NOTE: Fileref OSCMD has been deassigned.
30
31 GOPTIONS NOACCESSIBLE;
32 %LET _CLIENTTASKLABEL=;
33 %LET _CLIENTPROJECTPATH=;
34 %LET _CLIENTPROJECTNAME=;
35 %LET _SASPROGRAMFILE=;
36
37 ;*';*";*/;quit;run;
38 ODS _ALL_ CLOSE;
39
40
41 QUIT; RUN;
42

 

sasprofile
Quartz | Level 8

KurtBremser

 

Sorry typo error  *so it means the X command in EG is working

Kurt_Bremser
Super User

The X command/statement does not retrieve any output back into the SAS system.

So you won't get any information for

x 'ls -l;

x 'pwd';

The next two commands

x  'cd /home/xu84178';

x 'ls -l  >  ls.txt  ' ;

should create a list of files in (what I guess is) your home directory. Do a refresh on Files in the server list in EG to see if the file (ls.txt) is there.

Note that a cd command in the X statement will change the CWD of the SAS process. Executing it with the filename pipe method won't do that.

This indicates that SAS executes commands from X directly, while filename pipe uses a shell exit (therefore changes to the environment are lost when that sub-shell terminates)

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 14 replies
  • 7828 views
  • 1 like
  • 5 in conversation