BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
4 REPLIES 4
Peter_C
Rhodochrosite | Level 12
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
Cynthia_sas
SAS Super FREQ
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
deleted_user
Not applicable
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;
Olivier
Pyrite | Level 9
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

sas-innovate-2024.png

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.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 715 views
  • 0 likes
  • 4 in conversation