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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.