Help using Base SAS procedures

X command accessing work data set

Accepted Solution Solved
Reply
Super Contributor
Posts: 400
Accepted Solution

X command accessing work data set

I have a 3rd party tool that can export data into any format I want.  I'm trying to use the x command statement to execute this process.  The issue i'm having is that the data set is part of my sas session and does not exist on the local computer.  Can I pass this data set to this process through x command or do I have to save off the data set then access the data through the x command statement?

example code:

options noxwait ;

x 'C:\PROGRA~1\DataTrans\dt.exe work.temp  c:\temp\temp.xlsx';

Thank you


Accepted Solutions
Solution
‎07-02-2014 12:48 PM
Super User
Super User
Posts: 7,060

Re: X command accessing work data set

Posted in reply to jerry898969

If I understand your question then no.  The X command will run on the computer that SAS is running on.  So it can only call programs that are on that computer.  Now if this conversion program is on the computer which is running SAS then the X command will be able to run it.  You will just need to specify the filenames properly.

I find it best to quote filenames in Windows commands to make sure it doesn't get confused by embedded spaces in file or directory names.

I find it best to use DATA _NULL_ and PIPE to execute commands instead of using the X command.  That way the program can pull any error messages and save them in the SAS log instead of having them appear on some terminal window or disappear completely.

data _null_;

  length cmd $400 ;

  cmd=quote(catx(' '

       ,quote("C:\PROGRA~1\DataTrans\dt.exe")

       ,quote(catx('\',pathname('work'),'temp.sas7bdat'))

       ,quote("c:\temp\temp.xlsx")

      ))

  ;

  infile x pipe filevar=cmd end=eof;

  input ;

  put _infile_;

run;


View solution in original post


All Replies
Solution
‎07-02-2014 12:48 PM
Super User
Super User
Posts: 7,060

Re: X command accessing work data set

Posted in reply to jerry898969

If I understand your question then no.  The X command will run on the computer that SAS is running on.  So it can only call programs that are on that computer.  Now if this conversion program is on the computer which is running SAS then the X command will be able to run it.  You will just need to specify the filenames properly.

I find it best to quote filenames in Windows commands to make sure it doesn't get confused by embedded spaces in file or directory names.

I find it best to use DATA _NULL_ and PIPE to execute commands instead of using the X command.  That way the program can pull any error messages and save them in the SAS log instead of having them appear on some terminal window or disappear completely.

data _null_;

  length cmd $400 ;

  cmd=quote(catx(' '

       ,quote("C:\PROGRA~1\DataTrans\dt.exe")

       ,quote(catx('\',pathname('work'),'temp.sas7bdat'))

       ,quote("c:\temp\temp.xlsx")

      ))

  ;

  infile x pipe filevar=cmd end=eof;

  input ;

  put _infile_;

run;


Super Contributor
Posts: 400

Re: X command accessing work data set

Thank you so much Tom. Using pathname function on the work library and pointing to the data file was exactly what I needed.

🔒 This topic is solved and locked.

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

Discussion stats
  • 2 replies
  • 179 views
  • 0 likes
  • 2 in conversation