Help using Base SAS procedures

Update External File in Place

Reply
Occasional Contributor
Posts: 7

Update External File in Place

I would like to update values in an external file. The file is not a fixed length. The code drops the first character of the next line after it updates.. What will be a good way to do this?

Here is the code I use to update:
data _null_;
infile file lrecl=400 truncover sharebuffers pad;
file file;
input @72 id $ 9.;
set upd key=id/unique end=done;
if _IORC_=0 then put _infile_ @81 item;
else do;
_error_=0;
end;
run;
Super Contributor
Super Contributor
Posts: 3,174

Re: Update External File in Place

You have a hardcoded LRECL, yet you say that the incoming file "is not a fixed length". Also, your PUT statement does not show a format/length for the variable ITEM.

http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a000171874.htm

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic/post:
update external file inplace site:sas.com
Occasional Contributor
Posts: 7

Re: Update External File in Place

Thanks!!

LRECL for the max length even though the lines are different lengths.
Even with the variable length, the problem still exists..
Super Contributor
Super Contributor
Posts: 3,174

Re: Update External File in Place

I believe that you will need to read the file, writing to a new file, then replace (not in-place though) the original file. Suggest you review the DOC references, as well. And again share any updated/modified code with the forum as a post-reply, ideally in your SAS execution log, not just the code piece.

Explain the SAS environment and where the external file resides for additional guidance.

Also, I question the use of PAD, if you have variable-length data to copy - each PUT will pad the output record to the LRECL= amount specified, I believe. You should start with the bare minimum parameters and go from there.

Scott Barry
SBBWorks, Inc.

Message was edited by: sbb Message was edited by: sbb
Ask a Question
Discussion stats
  • 3 replies
  • 138 views
  • 0 likes
  • 2 in conversation