Sample 24782: Update an external file in place
Using a data set of changes, update an existing flat file.
When updating a RECFM=V external file in place, ensure that the
length of each logical record is not changed when fields'
values are changed. If the update operation shortens the
logical record, an additional end-of-record marker is written to the file. If lengthened, the updated record is overwrites data on the subsequent record if SHAREBUFFERS is used. Please refer to SAS Note
SN-009179 for more information.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
/* Create original file */
data _null_;
file "c:\temp\fox.txt";
put 'a quickbrownfox' /
'b quickbrownfox' /
'c quickbrownfox' /
'd quickbrownfox' /
'a quickbrownfox' /
'a quickbrownfox' ;
run;
/* Data set of changes to be made */
data color(index=(id));
input id $ color $;
datalines;
a green
d white
;
/* The INPUT statement brings a record into the input buffer. The */
/* value of ID for the current record populates KEY= to subset the */
/* look-up data set COLOR. If there is a match for ID between */
/* the flat file being read and the lookup data set, use the value */
/* of color to overwrite the text in the input buffer starting at */
/* column 9, then output the buffer. If there is not a match, */
/* reset the _ERROR_ variable. No new observations are written to */
/* the file. Iterate back to the top of the DATA step, and bring in */
/* the next record. */
data _null_;
infile "c:\temp\fox.txt" truncover sharebuffers;
file "c:\temp\fox.txt";
input @1 id $1. ;
set color key=id/unique end=done;
if _IORC_=0 then put _infile_ @9 color;
else do;
_error_=0;
end;
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
OUTPUT to external file
a quickgreenfox
b quickbrownfox
c quickbrownfox
d quickwhitefox
a quickgreenfox
a quickgreenfox
Using a data set of changes, update an existing flat file.
Type: | Sample |
Topic: | SAS Reference ==> DATA Step Common Programming Tasks ==> Reading and Writing External Data
|
Date Modified: | 2005-12-08 11:34:34 |
Date Created: | 2004-09-30 14:09:13 |
Operating System and Release Information
SAS System | Base SAS | All | n/a | n/a |