The SAS Output Delivery System and reporting techniques

Import File, Amend it, Export File

Reply
N/A
Posts: 0

Import File, Amend it, Export File

Hi All,

I need to "import" a text file into Sas, replace some text (using placeholders.. e.g. [&firstname], [&lastname] ) then save the amended file back to disk under a new name.

Firstly is this possible, secondly how?!!

Any help is greatly appreciated! Message was edited by: Paat
Valued Guide
Posts: 2,174

Re: Import File, Amend it, Export File

since you need to use SAS, I assume there is more to this than stated. It appears possible to do what you need in any editor ~ notepad upward.
Perhaps you can explain.
Since the enquiry seems unrelated to this (and the other SAS) forums, you may find the most effective answer will come from addressing the fuller form of your question to your SAS Customer Support service.

PeterC
SAS Super FREQ
Posts: 8,740

Re: Import File, Amend it, Export File

Hi:
This is not an ODS or Base Reporting proc question. You'll need the DATA step, INFILE and FILE statements, conditional logic, the INPUT statement, the PUT statement, and possibly the Macro facility (if you mean to use Macro variables) for your placeholder substitution.

Your best best for help with this question is to contact Tech Support. To find out how to contact Tech Support, refer to:
http://support.sas.com/techsup/contact/index.html

cynthia
N/A
Posts: 0

Re: Import File, Amend it, Export File

THis is how i achieved what i wanted...

/* LOAD IN HTML TEMPLATE */
data WORK.abcde;
infile 'C:\Folder\File.htm'
LINESIZE=32000 TRUNCOVER;
input line $char32000.;
run;

/* REPLACE TEXT */
data WORK.abcdef;
set WORK.abcde;
length linefix $ 32000;
rx=rxparse("'[_Fullname_]' to '&Fullname'");
call rxchange(rx,1,line,linefix);
run;

/* EXPORT */
data _null_;
file "C:\Folder\Output.htm";
set Work.abcdef;
put linefix;
run;
Super Contributor
Posts: 260

Re: Import File, Amend it, Export File

You can downsize your program using the automatic _INFILE_ variable that contains the line that is being read from the external file once the INPUT statement is executed.
So everything can be done into a single Data step, without writing into a SAS dataset :

data _NULL_ ;
* LOAD IN HTML TEMPLATE */
infile 'C:\Folder\File.htm' LINESIZE=32000 TRUNCOVER ;
input ;
/* REPLACE TEXT */
rx=rxparse("'[_Fullname_]' to '&Fullname'") ;
call rxchange(rx,1,_infile_,_infile_) ;
/* EXPORT */
file "C:\Folder\Output.htm" ;
put _infile_ ;
run ;

As well as being prettier and shorter to write, this will same you time if your input file is long.

Regards,
Olivier
Ask a Question
Discussion stats
  • 4 replies
  • 147 views
  • 0 likes
  • 4 in conversation