Sample 24701: Modify members of a PDS using a SAS DATA step
Read in all members of a PDS and make edits as necessary.
Note:
Use PROC SOURCE to generate a list of members and the INFILE
statement with FILEVAR= option to read all of the members.
While reading each member, modify the text where necessary and
write back out again.
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.
/* PDS you're reading from. For this sample there are three members: ONE */
/* contains 'APPLE', TWO contains 'BANANA' and THREE contains 'COCONUT'. */
filename in 'name.batch.jobs';
/* File where names of the members will be written */
filename out 'name.my.test';
/* Put the member names from the PDS into the OUT= location */
proc source dirdd=out indd=in nodata noprint;
run;
/* The first INFILE/INPUT reads each member name from the list of members. */
/* The FTRW variable holds the fully qualified PDS member name. Be sure */
/* that the length is long enough to contain the longest name. */
/* The second INFILE statement uses FILEVAR= to point to the PDS member. */
/* It also uses sharebuffers so that the file will be updated in place. */
/* The DO UNTIL goes through the entire file reading every record. Only */
/* those records that contain the target string are changed. */
data _null_;
infile out;
input name $;
length ftrw $50;
ftrw='name.batch.jobs('||trim(name)||')';
infile dummy filevar=ftrw sharebuffers end=done;
file dummy filevar=ftrw ;
do until(done);
input @1 fruit :$8. ;
if fruit='BANANA' then put @1 'berry ';
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.
NOTES in log
NOTE: The infile OUT is:
Dsname=NAME.MY.TEST,
Unit=3390,Volume=TSD004,Disp=SHR,Blksize=6160,
Lrecl=80,Recfm=FB
NOTE: The file/infile DUMMY is:
Dsname=NAME.BATCH.JOBS(ONE),
Unit=3390,Volume=TSD004,Disp=SHR,Blksize=6160,
Lrecl=80,Recfm=FB
NOTE: The file/infile DUMMY is:
Dsname=NAME.BATCH.JOBS(THREE),
Unit=3390,Volume=TSD004,Disp=SHR,Blksize=6160,
Lrecl=80,Recfm=FB
NOTE: The file/infile DUMMY is:
Dsname=NAME.BATCH.JOBS(TWO),
Unit=3390,Volume=TSD004,Disp=SHR,Blksize=6160,
Lrecl=80,Recfm=FB
NOTE: 3 records were read from the infile OUT.
NOTE: 1 record was read from the infile DUMMY.
NOTE: 1 record was read from the infile DUMMY.
NOTE: 1 record was read from the infile DUMMY.
NOTE: 0 records were written to the file DUMMY.
NOTE: 0 records were written to the file DUMMY.
NOTE: 1 record was written to the file DUMMY.
Read in all members of a PDS and make edits as necessary.
Type: | Sample |
Topic: | SAS Reference ==> DATA Step Common Programming Tasks ==> Utilities
|
Date Modified: | 2005-12-08 11:34:23 |
Date Created: | 2004-09-30 14:09:05 |
Operating System and Release Information
SAS System | Base SAS | z/OS | n/a | n/a |
CMS | n/a | n/a |