Opening and closing terminals with an "X statement"? (Or not opening them at all?)

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

Opening and closing terminals with an "X statement"? (Or not opening them at all?)

Hello, new-ish SAS user.

 

The trouble I'm having is this: whenever I need to use a lot of "X statements" (I don't know the proper terminology for this), for instance I need to create a bunch of folders in some directory, SAS opens a terminal for each and I have to shut it down manually, and I'd of course like to avoid this. There's obviously something I'm missing here.

 

For example, I want to make a bunch of folders folder1, folder2... folder100 within path C:\PATH. Here's the code I would use:

 

x "dir c:\PATH";

 

%macro makedirs;

  %do i=1 %to 100;

     x "md folder&i";

  %end;

%mend makedirs;

 

%makedirs

 

The problem is, I'm going to have to manually shut down 100 windows, when this should actually take no time at all. I've tried adding lines like:

x "exit";

but to no avail. How do I avoid this? Really, how do I tell SAS not to open a terminal window at all?


Accepted Solutions
Solution
‎02-14-2018 01:04 PM
Super User
Posts: 23,346

Re: Opening and closing terminals with an "X statement"? (Or not opening them at all?)

 

You have at least three options that I see:

Use the NoXSYNC/noxwait option.

http://support.sas.com/documentation/cdl/en/hostwin/69955/HTML/default/viewer.htm#n0xwt90ik8vxdrn137...

 

option noxwait;

Use SAS base libname trick to create folders

You can use the LIBNAME and DLCREATEDIR option.

https://blogs.sas.com/content/sasdummy/2013/07/02/use-dlcreatedir-to-create-folders/

Note that there's a LIBNAME function so that you don't need a macro here either.

 

 

Use the DCREATE() function to create a directory

http://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=p1aj29pf4cxnirn15q5hmf0tv438.htm&...

 

I'm more in favour of one of the latter options because they will work on most systems without being changed and because they don't need macro code. X commands are commonly locked down on many installations.

View solution in original post


All Replies
Occasional Contributor
Posts: 12

Re: Opening and closing terminals with an "X statement"? (Or not opening them at all?)

I'm using Windows 10, by the way.
Solution
‎02-14-2018 01:04 PM
Super User
Posts: 23,346

Re: Opening and closing terminals with an "X statement"? (Or not opening them at all?)

 

You have at least three options that I see:

Use the NoXSYNC/noxwait option.

http://support.sas.com/documentation/cdl/en/hostwin/69955/HTML/default/viewer.htm#n0xwt90ik8vxdrn137...

 

option noxwait;

Use SAS base libname trick to create folders

You can use the LIBNAME and DLCREATEDIR option.

https://blogs.sas.com/content/sasdummy/2013/07/02/use-dlcreatedir-to-create-folders/

Note that there's a LIBNAME function so that you don't need a macro here either.

 

 

Use the DCREATE() function to create a directory

http://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=p1aj29pf4cxnirn15q5hmf0tv438.htm&...

 

I'm more in favour of one of the latter options because they will work on most systems without being changed and because they don't need macro code. X commands are commonly locked down on many installations.

Occasional Contributor
Posts: 12

Re: Opening and closing terminals with an "X statement"? (Or not opening them at all?)

Thanks! I ended up using the DLCREATEDIR option, works like a charm!

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 169 views
  • 4 likes
  • 2 in conversation