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?
You have at least three options that I see:
Use the NoXSYNC/noxwait option.
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
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.
You have at least three options that I see:
Use the NoXSYNC/noxwait option.
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
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.
Thanks! I ended up using the DLCREATEDIR option, works like a charm!
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 25. 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.