IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Sortcard to put comma after particular word


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sakrat

Active User


Joined: 05 Feb 2014
Posts: 164
Location: India

PostPosted: Mon May 11, 2015 8:20 pm
Reply with quote

Hi,

I have below requirement like

dataset like below:

Code:


A,                ,C,D1 D2 D3,E,F
     B1 IN                           F
     B2 IN                           F
     B3 OUT                          F



Expected out dataset:

Code:


A,B1 IN B2 IN,B3 OUT,C,D1 D2 D3,E,F



Can some one please help me what kind of sort card do i need to use to get my expected output.


Thanks

[/code]
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon May 11, 2015 8:23 pm
Reply with quote

Which SORT product do you have?

What RECFM and LRECL? Is the input always a fixed structure like that?

How does what you wrote relate to the title you gave it?
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Mon May 11, 2015 8:25 pm
Reply with quote

And if you want a sort solution why post int the JCL section of the forum instead of the appropriate sort section?
Back to top
View user's profile Send private message
sakrat

Active User


Joined: 05 Feb 2014
Posts: 164
Location: India

PostPosted: Mon May 11, 2015 8:42 pm
Reply with quote

sorry for the wrong kind of info,

my input dataset is


Code:



A,B1 IN B2 IN B3 OUT,C,D1 D2 D3,E,F




expected output:

Code:


A,B1 IN B2 IN,B3 OUT,C,D1 D2 D3,E,F




commma(,) should be added after the last IN where the column position of last IN may vary.

can you please help me in thi... we ue syncsort and DFsort
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon May 11, 2015 8:54 pm
Reply with quote

Will the number of INs vary, or will there always be two?
Back to top
View user's profile Send private message
sakrat

Active User


Joined: 05 Feb 2014
Posts: 164
Location: India

PostPosted: Mon May 11, 2015 9:11 pm
Reply with quote

Bill Woodger wrote:
Will the number of INs vary, or will there always be two?



it will always be 2.but the column position will vary like sometimes it may be in 32 or sometime or where else..... so should find the last IN in the record.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon May 11, 2015 9:45 pm
Reply with quote

Use INREC with IFTHEN=(WHEN=INIT and FINDREP to change C' IN ' to (an example X'FFFFFFFF' use DO=1, very important, so that only the first is changed. Then another WHEN=INIT with FINDREP to make the change you want to the second IN (now the first), again with DO=1. Finally, a third WHEN=INIT and FINDREP to change X'FFFFFFFF' back to C' IN '.
Back to top
View user's profile Send private message
sakrat

Active User


Joined: 05 Feb 2014
Posts: 164
Location: India

PostPosted: Tue May 12, 2015 11:27 am
Reply with quote

Bill Woodger wrote:
Use INREC with IFTHEN=(WHEN=INIT and FINDREP to change C' IN ' to (an example X'FFFFFFFF' use DO=1, very important, so that only the first is changed. Then another WHEN=INIT with FINDREP to make the change you want to the second IN (now the first), again with DO=1. Finally, a third WHEN=INIT and FINDREP to change X'FFFFFFFF' back to C' IN '.


But I want only the last IN to be added with comma...not all IN's.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue May 12, 2015 11:42 am
Reply with quote

Really? And what happened when you coded up and tested my suggestion?

Are you now sure that there will always be two as you stated earlier?
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue May 12, 2015 12:12 pm
Reply with quote

Use INREC with IFTHEN=(WHEN=INIT and FINDREP to change C' IN ' to (an example X'FFFFFFFF' use DO=1, very important, so that only the first is changed.

Code:
OPTION COPY

INREC IFTHEN=(WHEN=INIT,
                FINDREP=(IN=C' IN ',
                       OUT=X'FFFFFFFF',
                       DO=1))


Then another WHEN=INIT with FINDREP to make the change you want to the second IN (now the first), again with DO=1.

Code:
OPTION COPY

INREC IFTHEN=(WHEN=INIT,
                FINDREP=(IN=C' IN ',
                       OUT=X'FFFFFFFF',
                       DO=1)),
      IFTHEN=(WHEN=INIT,
                FINDREP=(IN=C' IN ',
                       OUT=C' IN,',
                       DO=1))



Finally, a third WHEN=INIT and FINDREP to change X'FFFFFFFF' back to C' IN '.

Code:
OPTION COPY

INREC IFTHEN=(WHEN=INIT,
                FINDREP=(IN=C' IN ',
                       OUT=X'FFFFFFFF',
                       DO=1)),
      IFTHEN=(WHEN=INIT,
                FINDREP=(IN=C' IN ',
                       OUT=C' IN,',
                       DO=1)),
      IFTHEN=(WHEN=INIT,
                FINDREP=(OUT=C' IN ',
                       IN=X'FFFFFFFF',
                       DO=1))


Run each of those with this as the input, so you can understand what is happening:

Code:
 IN  IN  IN  IN  IN  IN
Back to top
View user's profile Send private message
sakrat

Active User


Joined: 05 Feb 2014
Posts: 164
Location: India

PostPosted: Tue May 12, 2015 6:04 pm
Reply with quote

Bill Woodger wrote:
Use INREC with IFTHEN=(WHEN=INIT and FINDREP to change C' IN ' to (an example X'FFFFFFFF' use DO=1, very important, so that only the first is changed.

Code:
OPTION COPY

INREC IFTHEN=(WHEN=INIT,
                FINDREP=(IN=C' IN ',
                       OUT=X'FFFFFFFF',
                       DO=1))


Then another WHEN=INIT with FINDREP to make the change you want to the second IN (now the first), again with DO=1.

Code:
OPTION COPY

INREC IFTHEN=(WHEN=INIT,
                FINDREP=(IN=C' IN ',
                       OUT=X'FFFFFFFF',
                       DO=1)),
      IFTHEN=(WHEN=INIT,
                FINDREP=(IN=C' IN ',
                       OUT=C' IN,',
                       DO=1))



Finally, a third WHEN=INIT and FINDREP to change X'FFFFFFFF' back to C' IN '.

Code:
OPTION COPY

INREC IFTHEN=(WHEN=INIT,
                FINDREP=(IN=C' IN ',
                       OUT=X'FFFFFFFF',
                       DO=1)),
      IFTHEN=(WHEN=INIT,
                FINDREP=(IN=C' IN ',
                       OUT=C' IN,',
                       DO=1)),
      IFTHEN=(WHEN=INIT,
                FINDREP=(OUT=C' IN ',
                       IN=X'FFFFFFFF',
                       DO=1))


Run each of those with this as the input, so you can understand what is happening:

Code:
 IN  IN  IN  IN  IN  IN




I tried with the code and the input which you mentioned. In the last code I get the output with comma included in the second position.

but what if my input is something like below :

Code:

 
IN  IN  IN   OUT  OUT  OUT



I want my output like below:

Code:


IN  IN  IN,  OUT  OUT  OUT

Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue May 12, 2015 6:21 pm
Reply with quote

Swathi Muralidharan wrote:
Bill Woodger wrote:
Will the number of INs vary, or will there always be two?



it will always be 2.but the column position will vary like sometimes it may be in 32 or sometime or where else..... so should find the last IN in the record.


That's why I asked.

So, will it always be two as you said when asked, or will it sometimes be other than two (like one, three, any amount greater than three)? If so, what are the rules for it?
Back to top
View user's profile Send private message
sakrat

Active User


Joined: 05 Feb 2014
Posts: 164
Location: India

PostPosted: Tue May 12, 2015 6:34 pm
Reply with quote

Bill Woodger wrote:
Swathi Muralidharan wrote:
Bill Woodger wrote:
Will the number of INs vary, or will there always be two?



it will always be 2.but the column position will vary like sometimes it may be in 32 or sometime or where else..... so should find the last IN in the record.


That's why I asked.

So, will it always be two as you said when asked, or will it sometimes be other than two (like one, three, any amount greater than three)? If so, what are the rules for it?



I thought you are asking about the length. My mistake very sorry....yeah it may occur many times not constant like for example in the dataset in first line of records there may be two IN and in the second line record there might be three or even more than that.

Example:

Code:


jobname1 IN  jobname2 IN  jobname3 IN jobname4 OUT
jobname1 IN  jobname2 IN  jobname3 OUT



Expected output :

Code:


jobname1 IN jobname2 IN  jobname3 IN, jobname4 OUT
jobname1 IN jobname3 IN, jobname3 OUT



In my expected output the comma should be included after the last IN condition.

Thanks,
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue May 12, 2015 7:27 pm
Reply with quote

OK, now that we've securely established that IN contains two characters...

"Last" is tricky. So I'm going to suggest you rearrange your data so that it is the first.
Code:

  OPTION COPY
                                                                       
  INREC IFTHEN=(WHEN=INIT,
           BUILD=(12,1,11,1,10,1,9,1,8,1,7,1,6,1,5,1,4,1,3,1,2,1,1,1)),
        IFTHEN=(WHEN=INIT,
                FINDREP=(IN=C' NI ',
                       OUT=C',NI ',
                       DO=1)),
        IFTHEN=(WHEN=INIT,
           BUILD=(12,1,11,1,10,1,9,1,8,1,7,1,6,1,5,1,4,1,3,1,2,1,1,1))
//SORTIN   DD *
 IN  IN  IN
 IN  IN
 IN
 OUT


That produces:

Code:
 IN  IN  IN,
 IN  IN,   
 IN,       
 OUT   


That's an example with 12 bytes of data. You can do the typing for your length of data. Now you're going to tell us they are variable-length records?
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Tue May 12, 2015 10:02 pm
Reply with quote

Are you sure it is
Quote:
after a particular word
- in this case IN and not
Quote:
before a particular word
- in this case OUT ,which is what it appears to be from the latest example? Does that make it easier?
Back to top
View user's profile Send private message
sakrat

Active User


Joined: 05 Feb 2014
Posts: 164
Location: India

PostPosted: Tue May 12, 2015 11:17 pm
Reply with quote

Bill Woodger wrote:
OK, now that we've securely established that IN contains two characters...

"Last" is tricky. So I'm going to suggest you rearrange your data so that it is the first.
Code:

  OPTION COPY
                                                                       
  INREC IFTHEN=(WHEN=INIT,
           BUILD=(12,1,11,1,10,1,9,1,8,1,7,1,6,1,5,1,4,1,3,1,2,1,1,1)),
        IFTHEN=(WHEN=INIT,
                FINDREP=(IN=C' NI ',
                       OUT=C',NI ',
                       DO=1)),
        IFTHEN=(WHEN=INIT,
           BUILD=(12,1,11,1,10,1,9,1,8,1,7,1,6,1,5,1,4,1,3,1,2,1,1,1))
//SORTIN   DD *
 IN  IN  IN
 IN  IN
 IN
 OUT


That produces:

Code:
 IN  IN  IN,
 IN  IN,   
 IN,       
 OUT   


That's an example with 12 bytes of data. You can do the typing for your length of data. Now you're going to tell us they are variable-length records?




its not like variable-length records. The IN may appear N number of times any where from column number 700 to 1179....So inbetween these i should find the last IN and put a comma after that...
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed May 13, 2015 12:53 am
Reply with quote

Well, that's great news. You only have to reverse that part (twice). Use STARTPOS and ENDPOS on the FINDREP as well.

Your alternative is PARSE. With IFTHEN=(WHEN=(logicalexpression to then test the PARSED fields to identify which is the last and then change that data and put the record back together again. You'd need a solid limit to the number of INs which can exist, and care when putting the record back together.
Back to top
View user's profile Send private message
sakrat

Active User


Joined: 05 Feb 2014
Posts: 164
Location: India

PostPosted: Wed May 13, 2015 11:59 am
Reply with quote

Bill Woodger wrote:
Well, that's great news. You only have to reverse that part (twice). Use STARTPOS and ENDPOS on the FINDREP as well.

Your alternative is PARSE. With IFTHEN=(WHEN=(logicalexpression to then test the PARSED fields to identify which is the last and then change that data and put the record back together again. You'd need a solid limit to the number of INs which can exist, and care when putting the record back together.



Sorry bill, I couldnt understand the below lines :

Quote:


(WHEN=(logicalexpression to then test the PARSED fields to identify which is the last and then change that data and put the record back together again.

Back to top
View user's profile Send private message
sakrat

Active User


Joined: 05 Feb 2014
Posts: 164
Location: India

PostPosted: Wed May 13, 2015 12:08 pm
Reply with quote

Bill Woodger wrote:
Well, that's great news. You only have to reverse that part (twice). Use STARTPOS and ENDPOS on the FINDREP as well.



Also reversing that part means, you mean the way like you have coded in the above post using BUILD right....? If that is the case it will take almost 300 as it starts from 700 to 1179 which is almost 300 difference. will that be fine, if I do like the above BUILD...?
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed May 13, 2015 12:10 pm
Reply with quote

To use the PARSE you'd need to know the maximum number of possible " IN " values, Then you test those PARSEd values, one test for each possible, in reverse order, and do the code to put the data with a comma "back" into the correct position within the current record.

If you're already processing the data in SAS, can't you do it there?
Back to top
View user's profile Send private message
sakrat

Active User


Joined: 05 Feb 2014
Posts: 164
Location: India

PostPosted: Wed May 13, 2015 12:14 pm
Reply with quote

Bill Woodger wrote:
To use the PARSE you'd need to know the maximum number of possible " IN " values, Then you test those PARSEd values, one test for each possible, in reverse order, and do the code to put the data with a comma "back" into the correct position within the current record.

If you're already processing the data in SAS, can't you do it there?



I am not familiar with SAS codes. This is the first time I am using SAS....is there any way to find the last IN and put comma after that using SAS....?
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed May 13, 2015 2:25 pm
Reply with quote

You're more familiar with SAS than I am, but I'd strongly suspect so.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Search two or more word with FILEAID Compuware & Other Tools 15
No new posts JCL sortcard to print only the records DFSORT/ICETOOL 11
No new posts replace word 'MONTH' with current mon... SYNCSORT 11
No new posts Sections: need one appearance of cer... DFSORT/ICETOOL 4
Search our Forums:

Back to Top