Hi Guys,
Is it possible to create a sas program file (initially without any code) in a given folder (library)?
Note: I am not asking about creating a dataset, I need to create a blank sas program file during run time. Like invoking a macro should automatically create a filename.sas program in a folder.
Regards,
Ramakanth
Yes, a SAS program is stored as a text file on disk which you can create in a DATA step. Why do you want to do this?
data _null_;
file pgm "C:\Temp\MySASProgram.sas";
put "* A Comment;";
run;
Yes, a SAS program is stored as a text file on disk which you can create in a DATA step. Why do you want to do this?
data _null_;
file pgm "C:\Temp\MySASProgram.sas";
put "* A Comment;";
run;
I just wanted to create a file and write a program using a macro. Sorry if that wasn't clear in the initial question.
With macro code you usually don't need to write program code to a separate file, you can just generate the code from within a SAS macro just by calling it:
data _null_;
file pgm "C:\Temp\MySASProgram.sas";
put "* A Comment;";
run;
%include "C:\Temp\MySASProgram.sas";
* Above code does exactly the same thing as the following macro;
%macro comment;
* A Comment;
%mend comment;
%comment;
You do not even need to write to a file, just use call execute, and no file writing involved. Saved I/O.
Can't see any reason to do this, but a data-step can do this:
data _null_;
file "PATH_TO_FILE\empty.sas";
run;
One way to go:
data _null_;
stop;
file 'c:\temp\test2.sas';
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.