Is there any ways to run Stata from within SAS? I have Stata installed on my PC.
Where is your SAS installed? If you have SAS installed on your PC you can start Stata from SAS using the X command. Not sure why you would want to do that rather than just starting Stata manually.
SAS is also installed on the same PC.
I am doing a long data processing job. Most of the tasks will be performed in SAS. Stata is very efficient to perform an intermediate task. Thus, I want to use Stata from within SAS to do that specific job and then import the generated data into SAS to do the remaining task. Can you please give an example of the x command?
x 'dir c:\*.*';
The X command allows you to run any command that works from a Windows command line. Within the quotes you just need to substitute the Stata command you wish to run. Test it first from a Windows command line or command window and once it works you can paste the command into your SAS program.
You need to first make up the stata sub-task so that it can be executed from one commandline command.
Then you can run that sub-task from within SAS like this.
data _null_;
infile "your_stata_commandline_here 2>&1" pipe;
input;
put _infile_;
run;
All messages from the stata execution (information, output and diagnostic) will end up in the SAS log. The X statement will not provide this information.
Sorry- I am still not clear about it. An example would have been great.
You must first find out how to run your stata task in batch.
Keep in mind that this here is the SAS communities, you won't find that much stata expertise here. I've never worked with stata.
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 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: