DATA Step, Macro, Functions and more

Read member from one PDS and write on another based on condition

Reply
New Contributor
Posts: 4

Read member from one PDS and write on another based on condition

[ Edited ]

Hi All,

 

I have a PDS 'userid.myname.other' with 3000 members I want to read all the members of that pds and write it in to a new PDS. I have few conditions for writing the members.

 

Conditions: 1. all the members have a particular name say sasexe on a fixed column but the row may varies. I want to start writing the members only when after sasexe all the lines before that has to be omitted.

                   2.  Likewise writing the output file has to be stopped when the when another keyword is encountered which is also common in all the members.

 

I'm attaching my sample code here. which is not working as expected. Can someone help me out on this?

 

code:

DATA TST1;
LENGTH FILENAME $40.;
INFILE FILE01;
INPUT @1 PGM $8.;
Inp_NAME = "input.file.name(" ||TRIM(PGM)|| ")";
out_NAME = "output.file.name(" ||TRIM(PGM)|| ")";
RUN;
DATA REC_OT(KEEP=REC);

LENGTH MYINFILE $400.;
SET TST1;
INFILE INDUMMY FILEVAR=Inp_NAME FILENAME=MYINFILE END=DONE;
DO WHILE(NOT DONE);
INPUT @1 REC $CHAR80.
@3 JOB $CHAR8.
@12JOB1 $CHAR4.;
INDIC=0;
INDIR=2;
IF (INDEX (JOB,"sasexe" ) > 0) THEN DO;
FILE OUTDUMMY FILEVAR=Out_NAME OLD;
PUT @1 REC;
IF (INDEX (JOB1,"EXEC") >0) THEN DO;
INDIC = INDIC+1;
END;
IF (INDIC = INDIR) THEN DO;
PUT "//*******";
DONE=1;
END;
END;

END;
FILE MESSAGES NOPRINT;
PUT 'FINISHED READING ' MYINFILE=;
RUN;

Super User
Super User
Posts: 9,416

Re: Read member from one PDS and write on another based on condition

What is a PDS?

Please provide test data in the form of a datastep in a code window (its the {i} above the post):

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

Please also provide what you expect to see from that test data.  

Please also avoid coding all in uppercase, its like shouting.

New Contributor
Posts: 4

Re: Read member from one PDS and write on another based on condition

Sorry for the Caps. Since we are working on Mainframe SAS I cannot avoid it. 

 

PDS is partitioned dataset which is used in mainframe as a folder. I will rephrase my question. 

 

Lets just consider a single file with 5 paragraphs.  I want to write a code to copy only the para that starts with SASEXE and ends with EXEC.

 

 

Super User
Posts: 9,890

Re: Read member from one PDS and write on another based on condition

From all I infer, it's about mainframe partitioned datasets, which also explains the uppercase coding. Although not necessary, many MF coders are still stuck in the 1950's.

 

I'd get hold a of a good JCL programmer and do it with MF text processing tools.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
New Contributor
Posts: 4

Re: Read member from one PDS and write on another based on condition

Posted in reply to KurtBremser

@KurtBremser  Yes, It can be done using JCLs but I have started learning SAS and would like to give a try using this SAS. 

 

We can assume my input like this for Opensource SAS.

 

 Jobstep4...... Hello all nice to learn sas ..... exec.

 Jobstep...... Hello all welcome to sas ..... exec.

 Jobstep2...... Hello everyone welcome to sas.... exec

 Jobstep.6..... Hello all sas is good ..... exec.

 

lets assume all the lines above are paragraphs and I need the para that starts with Jobstep2 and ends with exec .

 

PROC Star
Posts: 253

Re: Read member from one PDS and write on another based on condition

I can see a couple of errors in your code:

  • You forgot a left paranthesis in "output.file.name" ||TRIM(PGM)|| ")";
  • You put your filenames in INP_NAME and OUT_NAME, but your FILEVAR variables are named IDS_NAME and ODS_NAME

Not sure if that is enough to accomplish what you want, but it may help.

New Contributor
Posts: 4

Re: Read member from one PDS and write on another based on condition

@s_lassen Thanks for pointing things Lassen. But it didn't work after correcting those things. I'm almost done on this and will share the code once it is completed.

Ask a Question
Discussion stats
  • 6 replies
  • 89 views
  • 0 likes
  • 4 in conversation