|
View previous topic :: View next topic
|
| Author |
Message |
sakrat
Active User
Joined: 05 Feb 2014 Posts: 164 Location: India
|
|
|
|
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 |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
 |
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2454 Location: Hampshire, UK
|
|
|
|
| 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 |
|
 |
sakrat
Active User
Joined: 05 Feb 2014 Posts: 164 Location: India
|
|
|
|
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 |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
| Will the number of INs vary, or will there always be two? |
|
| Back to top |
|
 |
sakrat
Active User
Joined: 05 Feb 2014 Posts: 164 Location: India
|
|
|
|
| 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 |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
| 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 |
|
 |
sakrat
Active User
Joined: 05 Feb 2014 Posts: 164 Location: India
|
|
|
|
| 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 |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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:
|
|
| Back to top |
|
 |
sakrat
Active User
Joined: 05 Feb 2014 Posts: 164 Location: India
|
|
|
|
| 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:
|
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 |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
| 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 |
|
 |
sakrat
Active User
Joined: 05 Feb 2014 Posts: 164 Location: India
|
|
|
|
| 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 |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
 |
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2454 Location: Hampshire, UK
|
|
|
|
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 |
|
 |
sakrat
Active User
Joined: 05 Feb 2014 Posts: 164 Location: India
|
|
|
|
| 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 |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
 |
sakrat
Active User
Joined: 05 Feb 2014 Posts: 164 Location: India
|
|
|
|
| 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 |
|
 |
sakrat
Active User
Joined: 05 Feb 2014 Posts: 164 Location: India
|
|
|
|
| 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 |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
 |
sakrat
Active User
Joined: 05 Feb 2014 Posts: 164 Location: India
|
|
|
|
| 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 |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
| You're more familiar with SAS than I am, but I'd strongly suspect so. |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|