BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

13 REPLIES 13
Astounding
PROC Star

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";

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

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

Astounding
PROC Star

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";

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

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

Reeza
Super User

Post the exact code you submitted from @Astounding solution. 

Reeza
Super User

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. 

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

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";

 

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

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:  ***************************************************;
*****

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

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"';

 

Kurt_Bremser
Super User

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.

Reeza
Super User

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. 

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

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

 

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

cynthia

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 13 replies
  • 2487 views
  • 1 like
  • 5 in conversation