DATA Step, Macro, Functions and more

How do I Executing DOS Commands in BASE SAS

Accepted Solution Solved
Reply
Contributor VDD
Contributor
Posts: 22
Accepted Solution

How do I Executing DOS Commands in BASE SAS

Hello can someone assist me>

using the code below I am trying to do a file compare of 2 SAS programs to review the changes.

My issue is that the output file is not created.  But when I run the FC command line from DOS it works.

How would I write this to make it work in BASE SAS.

 

 

data _null_;

do;

x fc "R:\Programs_files.sas T:\Programs_files.sas > R:\changes.txt";

end;

run;

 


Accepted Solutions
Solution
‎01-13-2018 09:22 AM
Super User
Posts: 9,594

Re: How do I Executing DOS Commands in BASE SAS

To see if a command executed on the OS works, do this:

filename oscmd pipe 'fc /n R:\Programs_DRA2009\download\get_tanf_files.sas T:\Programs_DRA2009\download\get_tanf_files.sas 2>&1';

data _null_;
infile oscmd;
input;
put _infile_;
run;

This will catch all output (stdout and stderr) and write it to the SAS log.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

View solution in original post


All Replies
Super User
Posts: 6,542

Re: How do I Executing DOS Commands in BASE SAS

First, note that X is a SAS statement, but not a DATA step statement.  If you had a working X command, you could issue just the one line program:

 

x fc "R:\Programs_files.sas T:\Programs_files.sas > R:\changes.txt";

 

However, the X command requires that its argument be in quotes.  In this case, you could simply add the quotes:

 

x 'fc "R:\Programs_files.sas T:\Programs_files.sas > R:\changes.txt"';

 

Another possibility here would be to switch from X to %SYSEXEC, which performs similar functions but does not requires quotes::

 

%sysexec fc "R:\Programs_files.sas T:\Programs_files.sas > R:\changes.txt";

Contributor VDD
Contributor
Posts: 22

Re: How do I Executing DOS Commands in BASE SAS

Posted in reply to Astounding

I have tried both solutions but nether of them create a text output file.

Super User
Posts: 6,542

Re: How do I Executing DOS Commands in BASE SAS

I'm not too familiar with DOS commands, but this syntax strikes me as strange:

 

%sysexec fc "R:\Programs_files.sas T:\Programs_files.sas > R:\changes.txt";

 

Shouldn't it look more like this (or some other similar variation such as no quotes at all)?

 

%sysexec fc "R:\Programs_files.sas T:\Programs_files.sas" > "R:\changes.txt";

Contributor VDD
Contributor
Posts: 22

Re: How do I Executing DOS Commands in BASE SAS

Posted in reply to Astounding

the extra set of quotes doesn't resolve and create an output text file.

Super User
Posts: 22,857

Re: How do I Executing DOS Commands in BASE SAS

Post the exact code you submitted from @Astounding solution. 

Super User
Posts: 22,857

Re: How do I Executing DOS Commands in BASE SAS

And check if you have XCMD enabled. 

 

Proc options option =xcmd; run; 

 

If you don’t have xcmd enabled you can’t execute system commands. 

Contributor VDD
Contributor
Posts: 22

Re: How do I Executing DOS Commands in BASE SAS

these are the code I have used after the replies for help

Proc options option =xcmd; run;

data _null_;

do;

x 'fc /n"R:\Programs_DRA2009\download\get_tanf_files.sas T:\Programs_DRA2009\download\get_tanf_files.sas > R:\vdd_changes.txt"';

end;

run;

 

 

 

%sysexec fc "R:\Programs_DRA2009\download\get_tanf_files.sas T:\Programs_DRA2009\download\get_tanf_files.sas > R:\vdd_changes.tx";

 

Contributor VDD
Contributor
Posts: 22

Re: How do I Executing DOS Commands in BASE SAS

when I run the type the code on a DOS command line it works

and I get a file that contains this information.  I would like to run

fc R:\Programs_DRA2009\download\get_tanf_files.sas T:\Programs_DRA2009\download\get_tanf_files.sas > R:\vdd_changes.txt from a SAS session and use a macro for the filenames.

 

Comparing files R:\PROGRAMS_DRA2009\DOWNLOAD\get_tanf_files.sas and T:\PROGRAMS_DRA2009\DOWNLOAD\GET_TANF_FILES.SAS
***** R:\PROGRAMS_DRA2009\DOWNLOAD\get_tanf_files.sas
   81:  *
   82:  ***************************************************;
***** T:\PROGRAMS_DRA2009\DOWNLOAD\GET_TANF_FILES.SAS
   81:  *
   82:  *              01/12/2018 changed the filepath from \\dshsapoly80801\tanf_report
   83:  *                         to \\dshs\rda\tanf2018 in the libname statement and
   84:  *                         the renaming process. (M. Harris)
   85:  *                         
   86:  ***************************************************;
*****

Contributor VDD
Contributor
Posts: 22

Re: How do I Executing DOS Commands in BASE SAS

I have also used this

 

 

 

%sysexec 'fc "R:\Programs_DRA2009\download\get_tanf_files.sas T:\Programs_DRA2009\download\get_tanf_files.sas > R:\vdd_changes.txt"';

 

and this

 

 

%sysexec 'fc "R:\Programs_DRA2009\download\get_tanf_files.sas T:\Programs_DRA2009\download\get_tanf_files.sas" > "R:\vdd_changes.txt"';

 

Solution
‎01-13-2018 09:22 AM
Super User
Posts: 9,594

Re: How do I Executing DOS Commands in BASE SAS

To see if a command executed on the OS works, do this:

filename oscmd pipe 'fc /n R:\Programs_DRA2009\download\get_tanf_files.sas T:\Programs_DRA2009\download\get_tanf_files.sas 2>&1';

data _null_;
infile oscmd;
input;
put _infile_;
run;

This will catch all output (stdout and stderr) and write it to the SAS log.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 22,857

Re: How do I Executing DOS Commands in BASE SAS

Output from PROC OPTIONS? I suspect XCMD is enabled to allow you to run these types of commands. 

EG has this turned off by default. 

Contributor VDD
Contributor
Posts: 22

Re: How do I Executing DOS Commands in BASE SAS

Can you assist in telling me how to get EG to turn it on, or is there an option to turn it on in EG.

I use Base SAS

 

SAS Super FREQ
Posts: 9,259

Re: How do I Executing DOS Commands in BASE SAS

Hi:
I think that only your SAS Administrator can enable X commands for you. This is typically something that the Admin controls.

cynthia
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 13 replies
  • 248 views
  • 0 likes
  • 5 in conversation