The script uses the `CLASS` dataset from the internal `SASHELP` library.
1 Code Block
MACRO DEFINITION
Explanation : This block defines the `create_newfolder` macro. It takes one argument `newfld` (the path to the folder to create). It uses `%sysfunc(fileexist())` to check if the folder already exists. If not, it uses `%sysexec` with `md` (for Windows) or `mkdir -p` (for Linux) to create the folder. The use of `%sysexec` is an administrative function allowing system commands execution and requires appropriate privileges.
Copied!
%macro create_newfolder(newfld);
%*---------------------------------------------------------;
%*check for the existence of the folder;
%*---------------------------------------------------------;
%if %sysfunc(fileexist(&newfld)) %then %put NOTE:The directory "&newfld" already EXISTS.;
%*---------------------------------------------------------;
%*create the folder(s) recursively if absent;
%*---------------------------------------------------------;
%else %do;
%*---------------------------------------------------------;
%*check the operating system and use the OS specific command;
%*---------------------------------------------------------;
%if "%bquote(%substr(&sysscp,1,3))"="WIN" %then %sysexec md "&newfld";
%else %if "%bquote(%substr(&sysscp,1,3))"="LIN" %then %sysexec mkdir -p "&newfld";
%put NOTE:The directory "&newfld" has been CREATED.;
%end;
%mend csg_create_newfolder_001;
%put NOTE:The directory "&newfld" has been CREATED.;
20
%END;
21
22
23
%mend csg_create_newfolder_001;
2 Code Block
MACRO CALL / LIBNAME
Explanation : This block calls the `create_newfolder` macro to create the `D:\SAS\mactest` folder. Then, it assigns the `mylib` library name to this new folder, making it accessible for SAS operations.
Explanation : This DATA STEP block copies the `CLASS` dataset from the SASHELP library (implicitly, as `set class;` without a qualified libname refers to `SASHELP.CLASS` if `WORK.CLASS` does not exist) to the new `mylib` library, thereby creating `mylib.class` in the `D:\SAS\mactest` folder.
Copied!
data mylib.class;
set class;
run;
1
DATA mylib.class;
2
SET class;
3
RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.