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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 3 replies
  • 538 views
  • 4 likes
  • 2 in conversation