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.
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 '.
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.
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?
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.
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?
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...
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.
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.
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...?
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?
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....?