Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mx_createfile.sas File Reference

Creates a file in the logical filesystem of the target platform. More...

Go to the source code of this file.

Detailed Description

When building applications that run on multiple flavours of SAS, it is convenient to use a single macro (like this one) to write a text file - eg a settings file - without worrying about the platform primitive.

The file is created in the logical filesystem of the target platform (SAS Content folder, SASjs Drive, or metadata folder). No file is created on a physical filesystem. Platform behaviour:

  • SASVIYA: creates a SAS Content file (mv_createfile)
  • SASJS: creates a file on SASjs Drive (ms_createfile)
  • SAS 9 / metadata: SAS 9 has no "file" concept for Stored Process content, so a type 2 Stored Process is created in metadata (mm_createstp), with the content loaded as the STP source code

The alternative would be to compile a generic macro in target-specific folders (SASVIYA, SAS9 and SASJS). This avoids compiling unnecessary macros at the expense of a more complex sasjsconfig.json setup.

Usage:

filename ft15f001 temp;
data _null_;
  file ft15f001;
  put '%let mysetting=42;';
run;

%* viya:  /Public/app/myapp/settings (Files Service)      ;
%* sasjs: /Public/app/myapp/settings.sas (SASjs Drive)    ;
%* sas9:  /User Folders/sasdemo/myapp/settings (metadata) ;
%let filepath=/Public/app/myapp/settings;
%mx_createfile(&filepath, inref=ft15f001)
Parameters
[in]filepathThe full path of the file to create, INCLUDING the filename (must contain at least one / delimiter). On SASjs Server the name should carry the .sas extension if it will be executed as a Stored Program.
[in]inref=(0) The fileref containing the file content. A valid fileref is mandatory - if omitted, the macro aborts with an error.
[in]mdebug=(0) Set to 1 to enable DEBUG messages

SAS Macros

Related Macros

Definition in file mx_createfile.sas.