%macro CheckandCreateDir(dir);
options noxwait;
%local rc fileref ;
%let rc = %sysfunc(filename(fileref,&dir)) ;
%if %sysfunc(fexist(&fileref)) %then
%put The directory "&dir" already exists ;
%else
%do ;
%sysexec mkdir "&dir" ;
%if &sysrc eq 0 %then %put The directory &dir has been created;
Can anyone briefly explain what's going on.
I understood its creating a directory and checking whether it exits with IF ELSE statements.
but am not sure what exactly NOXWAIT option and in the very last IF statement &sysrc is doing ?
The documentation you linked is about the SYSRC() data step function, not the automatic macro variable, but both do in essence the same thing: report the return code of certain interactions with the operating system.
In your code, the %IF where &SYSRC is used checks if the external call to mkdir succeeded. Today you would use the DCREATE() data step function instead.
And what is your question?
Please post code as text by copying it into a window opened with the "little running man" icon.
This is an old macro that is NO longer required in SAS. You can use either DCREATE() or the option on the libname statement to create the folder.
SAS is an old language so it's easy to find old stuff - 30 years old sometimes around.
I've commend the code below but it's only partial code that you've posted.
%macro CheckandCreateDir(dir);
*if you don't have this option a dos window will pop up and you have to exit it manually;
options noxwait;
*creates a local macro variable;
%local rc fileref ;
*captures the Return Code (RC) from creating a filename reference;
*check the documentation to see what the differnet return codes mean;
%let rc = %sysfunc(filename(fileref,&dir)) ;
*checks if it already exists;
%if %sysfunc(fexist(&fileref)) %then
%put The directory "&dir" already exists ;
%else
%do ;
*if it does not exist it makes the directory using a mkdir command;
%sysexec mkdir "&dir" ;
%if &sysrc eq 0 %then %put The directory &dir has been created;
One of the nicer thing about the old SAS code you find, especially related to file manipulation or data step, is that most of it still works.
I am glad that I don't have to "forget" the coding I learned for SAS in the 1980's. Unlike when I worked in a shop that used SPSS where every annual update cycle seemed to require redesigning code and rewriting because one or more of the key elements our shop used was removed or the syntax drastically changed.
When things are built rather well from the start, there's no need for up-ending everything.
All books I ever bought about things Microsoft have long gone into the recycling bin, but Ken Thompson's The UNIX Operating System and the classic Kernighan-Richie are still useful parts of my bookshelf.
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: