DATA Step, Macro, Functions and more

Create a blank SAS program file at execution time

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

Create a blank SAS program file at execution time

[ Edited ]

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

 

 


Accepted Solutions
Solution
‎06-21-2018 01:35 AM
Super User
Posts: 3,927

Re: Create a blank SAS program file at execution time

Posted in reply to Ramakanthkrovi

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


All Replies
Solution
‎06-21-2018 01:35 AM
Super User
Posts: 3,927

Re: Create a blank SAS program file at execution time

Posted in reply to Ramakanthkrovi

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;
Occasional Contributor
Posts: 7

Re: Create a blank SAS program file at execution time

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

Super User
Posts: 3,927

Re: Create a blank SAS program file at execution time

[ Edited ]
Posted in reply to Ramakanthkrovi

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;
Super User
Super User
Posts: 9,599

Re: Create a blank SAS program file at execution time

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

Valued Guide
Posts: 580

Re: Create a blank SAS program file at execution time

Posted in reply to Ramakanthkrovi

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

 

data _null_;
   file "PATH_TO_FILE\empty.sas";
run;
Respected Advisor
Posts: 4,737

Re: Create a blank SAS program file at execution time

Posted in reply to Ramakanthkrovi

One way to go:

data _null_;
  stop;
  file 'c:\temp\test2.sas';
run;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

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