05-11-2017 06:29 PM - edited 05-11-2017 06:37 PM
Hello all;
I want use data step generate external file. the put statment does not work(need to keep the enter between rows) and need to be revised. please help.(I don't want add "put" in each line, because the real program has hundreds lines of codes)
Thank you!
Filename need "c:\temp\newcode.sas"; data _null_; file need; *------------ the code below need to be print to external file "newcode.sas*"------------------; put " /*Program name newcode.sas*/ /*This SAS program will print sashelp.class*/ proc print data=sashelp.class; run; "; *-----------------------end -------------------------------; run;
05-15-2017 11:59 AM - edited 05-15-2017 03:54 PM
*----------------C:\temp\test\aa.txt--------------------------------;
/*Program name newcode.sas*/
/*This SAS program will print sashelp.class*/
proc print data=sashelp.class;
run;
data a;
set sashelp.class;
run;
*----------------------------------------------;
data textdata; infile "C:\temp\test\aa.txt" truncover; input textline $100.; run; data textdata2; length z $200; set textdata; z=cat("put '",strip(textline),"';"); run; data textdata3; set textdata2; file "C:\temp\test\aa2.txt"; put z; run; data _null_; file 'C:\temp\test\aa3.sas'; %include "C:\temp\test\aa2.txt"; run;
Thank you!
Also thank Tom's good code,that works better:
data _null_;
file "c:\temp\newcode72.sas" ;
input;
put _infile_;
cards4;
/*Program name newcode.sas*/
/*This SAS program will print sashelp.class*/
proc print data=sashelp.class;
run;
data a;
set sashelp.class;
run;
;;;;
05-11-2017 06:38 PM
Have you looked into PROC PRINTTO?
You need to put the text in quotes to output it.
05-11-2017 06:41 PM
As you've seen, each PUT statement writes to one line (at least, by default). That gives you one possible solution: multiple PUT statements:
put "/*Program name newcode.sas*/"; put "/*This SAS program will print sashelp.class*/"; put "proc print data=sashelp.class;";
put "run;";
Not elegant, but at least it works. Alternatively, a slash in a PUT statements tells SAS to move to the next line. That means a single PUT statement can write out multiple pieces of text, to multiple lines, in this fashion:
put "/*Program name newcode.sas*/"
/ "/*This SAS program will print sashelp.class*/"
/ "proc print data=sashelp.class;"
/ "run;"
;
05-11-2017 06:43 PM
Are you just trying to write out to a text file the SAS program code you want?
One put statement will only generate one end of line unless you embedd the appropriate character(s) as a variable
Try:
data _null_; file need; *------------ the code below need to be print to external file "newcode.sas*"------------------; put "/*Program name newcode.sas*/"; put "/*This SAS program will print sashelp.class*/"; put "proc print data=sashelp.class;"; put "run;"; *-----------------------end -------------------------------; run;
05-11-2017 06:56 PM
http://www2.sas.com/proceedings/forum2007/037-2007.pdf
My guess is you're trying to accomplish something similar to this.
05-11-2017 07:10 PM
Given your example, what do you want the result to look like?
Art, CEO, AnalystFinder.com
05-11-2017 10:33 PM - edited 05-11-2017 10:34 PM
I want to create a new SAS program "c:\temp\newcode.sas" The full codes inside the file is:
/*Program name newcode.sas*/
/*This SAS program will print sashelp.class*/
proc print data=sashelp.class;
run;
data a;
set sashelp.class;
run;
My question is I can use data _null_ step to create the file? Thanks!
05-11-2017 10:58 PM
data _null_; file 'c:\temp\newcode.sas'; put ' /*Program name newcode.sas*/'; put '/*This SAS program will print sashelp.class*/'; put 'proc print data=sashelp.class;'; put 'run;'; put 'data a;'; put 'set sashelp.class;'; put 'run;'; run;
Art, CEO, AnalystFinder.com
05-15-2017 12:48 PM
As long as you are not running in a macro and the program code you want to copy does not include four semi-colons then you can use inline data.
data _null_;
file "c:\temp\newcode.sas" ;
input;
put _infile_;
cards4;
/*Program name newcode.sas*/
/*This SAS program will print sashelp.class*/
proc print data=sashelp.class;
run;
data a;
set sashelp.class;
run;
;;;;
05-12-2017 02:15 AM
05-15-2017 11:59 AM - edited 05-15-2017 03:54 PM
*----------------C:\temp\test\aa.txt--------------------------------;
/*Program name newcode.sas*/
/*This SAS program will print sashelp.class*/
proc print data=sashelp.class;
run;
data a;
set sashelp.class;
run;
*----------------------------------------------;
data textdata; infile "C:\temp\test\aa.txt" truncover; input textline $100.; run; data textdata2; length z $200; set textdata; z=cat("put '",strip(textline),"';"); run; data textdata3; set textdata2; file "C:\temp\test\aa2.txt"; put z; run; data _null_; file 'C:\temp\test\aa3.sas'; %include "C:\temp\test\aa2.txt"; run;
Thank you!
Also thank Tom's good code,that works better:
data _null_;
file "c:\temp\newcode72.sas" ;
input;
put _infile_;
cards4;
/*Program name newcode.sas*/
/*This SAS program will print sashelp.class*/
proc print data=sashelp.class;
run;
data a;
set sashelp.class;
run;
;;;;
Need further help from the community? Please ask a new question.