BookmarkSubscribeRSS Feed
DPraba79
Calcite | Level 5
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?
11 REPLIES 11
deleted_user
Not applicable
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
deleted_user
Not applicable
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.
deleted_user
Not applicable
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).
Warren
Obsidian | Level 7
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
Cynthia_sas
SAS Super FREQ
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
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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
Warren
Obsidian | Level 7
//* 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
deleted_user
Not applicable
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..
Warren
Obsidian | Level 7
* 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;
deleted_user
Not applicable
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.
Warren
Obsidian | Level 7
//* 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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 11 replies
  • 3227 views
  • 0 likes
  • 5 in conversation