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

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

 

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

3 REPLIES 3
Schwa
Fluorite | Level 6
I'm using Windows 10, by the way.
Reeza
Super User

 

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.

Schwa
Fluorite | Level 6

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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