Desktop productivity for business analysts and programmers

read & Update a member in PDS

Reply
Contributor
Posts: 34

read & Update a member in PDS

Hi,

I have a PDS with 10 members. I have to scan the symbol "&" in every record in these 10 member. If i found, i have to replace with AND. I have a string function to do this, however i have to read the member and update the member, I don't know how to do this. Could you please help me?
N/A
Posts: 0

Re: read & Update a member in PDS

For a start, you can use a filename statement defined to the PDS, then the members are referenced by (member)

filename pds "&path";

data _null_;
infile pds(member);
file pds(member);
input;
/* modify */
put;
run;
quit;

The next thing you need to know is the use of the sharebuffers option.
Then use the _infile_ buffer or a variable which points to the buffer using the _infile_ option.

The SAS documentation for the INFILE statement has a section specifically on "Updating External Files in Place", and an example.

Read and experiment. null
N/A
Posts: 0

Re: read & Update a member in PDS

A very good set of pointers given here Chuck. My concern however is that text substringing and replacement is a task that is prone to errors.

I would suggest it is safer to write to a different catalogue with the same member name and verify the replacements are happening as expected. Indeed, the robust solution would be to write to another catalogue and then rename the original to an "archive" name and rename the new one to replace the original. Much safer.

As a first observation, a single character is being replaced with three characters, which may extend the length of the line beyond the PDS maximum. Generally a PDS has 80 bytes, with 8 bytes reserved for line numbering. A 79 byte line will become 81 bytes and the character lost off the end could be a semi colon, or a closing quotation mark. Either would be hazardous.

The change of an ampersand also suggests any references to macros would be changed as well, and I am wondering whether the change should be " & " to " AND ". Otherwise a word with an ampersand in the string will change such as a favourite indulgence going from "M&M" to M AND M". It is innocuous in that example but may not be for data that deals with medical procedures like "D&C".

So, I'd use the non destructive approach until I verified my code replacement worked.
N/A
Posts: 0

Re: read & Update a member in PDS

Absolutely !

Test the code and process first, and be sure to think of all the Murphyisms (things that could go wrong) you can and test for them.

But, I expect that he may not want to replace/copy all the members in the PDS.
I am assuming the PDS is on a mainframe. z/OS control of a PDS goes back farther than MVS. If I were in ISPF and manually edited a PDS member, what really happens is a new instance of the member is created and appended to the file. You have to run a compacting (compress?) procedure to clean up a PDS file to remove all the old "versions" of modified members. Because of this, I assume that when doing an "inplace" update of a member with SAS, the same thing will occur. The fact of FILE PDS(member) I believe will cause a new version of "member" to be created/appended to the PDS file.

It has been a few years since I used a mainframe, but I remember inherting a number of PDS's that had gotten huge, and while tech support was going to grow the allocation, I instead ran the compaction (compress?) and the files reduced in size by a huge amount (> 10x?, it's been a long time).
Contributor
Posts: 28

Read & Update ALL members in PDS

I wonder if there's anyway that we can use a mainframe SAS program to read each member of a pds in a loop, make the same changes in each member, and write the result into another pds with the same members?

Thanks.

Warren
SAS Super FREQ
Posts: 8,721

Re: Read & Update ALL members in PDS

Hi:
I believe there is an example of this in the book entitled,"Reading external data files using SAS" by Michele M. Burlew.
http://www.sas.com/apps/pubscat/bookdetails.jsp?catid=1&pc=58369
Look at the Table of Contents for Chapter 4.

Also, this Tech Support note shows how to get a list of PDS members for use with a FILEVAR statement:
http://support.sas.com/techsup/technote/ts581.pdf

Also, if you were going to automate reading and writing PDS members in order to make specific changes, you might need to use the SAS Macro facility in order to make your programs more flexible. This paper is a good introduction to the SAS Macro facility:
http://www2.sas.com/proceedings/sugi28/056-28.pdf

cynthia
Super Contributor
Super Contributor
Posts: 3,174

Re: Read & Update ALL members in PDS

Suggest that you allocate the PDS library with DISP=OLD while processing the members (potential contention and member-level corruption/overlay are considerations). And also consider reading the PDS, creating a temporary PDS library, and then replace the members' contents, in case you may have some type of processing error along the way (before completion) -- remember to verify that you have a "current" backup copy each time you start the process.

Also, to the OP: you piggy-backed on someone else's very old post - a better approach is to author your own post and as needed include link(s) to prior posts or topic/subject reference for keeping your contribution separate from another individual's post.

Scott Barry
SBBWorks, Inc. Message was edited by: sbb
Contributor
Posts: 28

Re: Read & Update ALL members in PDS

//* I got the following solution from SAS technical support:
//SASSTEP EXEC SAS
//JCLIN DD DSN=YOUR.TEST.PDSIN,DISP=SHR
//JCLOUT DD DSN=YOUR.TEST.PDSOUT,DISP=OLD
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
FILENAME OUT '&TEMP'; RUN;
PROC SOURCE INDD=JCLIN NODATA NOPRINT DIRDD=OUT;
RUN;
/* PRODUCE GLOBAL VAR LIST OF MEMBERS TO AMEND */
DATA _NULL_;
INFILE OUT END=EOF;
INPUT MEMBER $8. ;
CALL SYMPUT('MEM'||LEFT(PUT(_N_,4.)),MEMBER);
IF EOF THEN DO;
CALL SYMPUT('MEMMAX',PUT(_N_,4.));
PUT 'MEMMAX=' _N_;
END;
RUN;
OPTIONS NONOTES;
%MACRO COMMEM;
%DO I = 1 %TO &MEMMAX;
%PUT &&MEM&I;
DATA _NULL_;
INFILE JCLIN(&&MEM&I) END=EOF;
FILE JCLOUT(&&MEM&I) NOPRINT NOTITLES;
INPUT JCLCARD $CHAR80.;
/* make changes to JCLCARD here */
PUT JCLCARD $CHAR80.;
RUN;
%END;
%MEND COMMEM;
%COMMEM;

Message was edited by: Warren Message was edited by: Warren
N/A
Posts: 0

Re: Read & Update ALL members in PDS

Hi,

Could you please let me know how did you add the find and replace functionality in PDS members, using the above macro?

Thanks in Advance..
Contributor
Posts: 28

Re: Read & Update ALL members in PDS

* My code for find & replace follows;
FIRST = index(line,'%');
DO WHILE (FIRST > 0);
/* AT LEAST 1ST OF PAIR FOUND. */
/* FIND 2ND OF PAIR */
len = index(substr(LINE,first+1),'%') + 1;
if (len > 1) THEN do;
/* FOUND THE 2ND OF THE PAIR. */
/* GET THE VARIABLE NAME AND SEARCH THE ARRAY FOR IT. */
kw = SUBSTR(LINE, FIRST, len);
dat = put(kw,$kw.);
if dat = 'unknown' then do;
dttm = datetime();
file logerr;
put dttm datetime18. " Member &&mem&i.. Keyword "
kw ' not found.';
first = 0;
end;
else do;
substr(line,first) = trim(dat) || substr(line,first+len);
FIRST = index(LINE,'%');
end;
END;
else first = 0;
END;
N/A
Posts: 0

Re: Read & Update ALL members in PDS

Hi Warren,

That was very useful. Thanks.

I also need to know how to pass a pds member as input and do a find and replace functionality and write it as another pds member. Could you please help me here too.
Contributor
Posts: 28

Re: Read & Update ALL members in PDS

//* The following pass the pds member MEMNAME as input
//MEM DD *
MEMNAME
/*

* You need to change part of the program above to the following;
DATA _NULL_;
INFILE mem END=EOF;
INPUT MEMBER $8. ;
call symput ('MEM'||TRIM(LEFT(PUT(_n_,4.))),member);
IF EOF THEN DO;
CALL SYMPUT('MEMMAX',TRIM(LEFT(PUT(_n_,4.))));
PUT 'MEMMAX=' _n_;
END;
RUN;
Ask a Question
Discussion stats
  • 11 replies
  • 1136 views
  • 0 likes
  • 5 in conversation