BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ramakanthkrovi
Obsidian | Level 7

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

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;

View solution in original post

6 REPLIES 6
SASKiwi
PROC Star

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;
Ramakanthkrovi
Obsidian | Level 7

I just wanted to create a file and write a program using a macro. Sorry if that wasn't clear in the initial question.

SASKiwi
PROC Star

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;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You do not even need to write to a file, just use call execute, and no file writing involved.  Saved I/O.

andreas_lds
Jade | Level 19

Can't see any reason to do this, but a data-step can do this:

 

data _null_;
   file "PATH_TO_FILE\empty.sas";
run;
Patrick
Opal | Level 21

One way to go:

data _null_;
  stop;
  file 'c:\temp\test2.sas';
run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 2384 views
  • 2 likes
  • 5 in conversation