Discussion:
Test for equality of more than one value
(too old to reply)
Robert Prins
2015-09-14 19:10:27 UTC
Permalink
Raw Message
Hi all,

Can anyone come up with a smart way of telling me if all values in a series
are equal? The length of the series ranges from 1 to potentially about 200+
(although in practice the longest series currently counts 15 values)

The format of the series is '{Z-' followed by ID (3
characters)/space/number (sign+2digits)/space sets, so e.g.

{X-AA +00 B +00 CC +00 D +00
{X-AA +00 B +00 CC +00 D +00 E +00 FF +01 G +00
{X-AA +00 B +00 CC +00 D +00 H +00 II +00 JJ +01
{X-AA +00 B +00 CC +00 D +00 H +00 II +00 KK +01 LL +01 JJ +01
{X-AA +00 B +00 H +00 II +00
{X-AA +00 B +00 H +00 II +00 JJ +01 CC +00 D +00
{X-MM -01
{X-NN -08

I need to flag those where the number is not the same for all ID's.

If all values are 00, a simple

if string = translate(string, '000000000', '1234566789') then

works, but it (obviously) fails for cases where all values are the same,
but not +00. One added complication is that the space following the number
may in future be replaced by a space, or 'a', or 'b', or 'c', or 'd'.

Robert
--
Robert AH Prins
***@gmail.com

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Walter Pachl
2015-09-14 20:51:13 UTC
Permalink
Raw Message
Is this your Input?
Can you show the expected result?
--
Walter

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Robert Prins
2015-09-14 21:11:30 UTC
Permalink
Raw Message
All I need to know is if the numerical values are the same, so

** {X-AA +00 B +00 CC +00 D +00
{X-AA +00 B +00 CC +00 D +00 E +00 FF +01 G +00
{X-AA +00 B +00 CC +00 D +00 H +00 II +00 JJ +01
{X-AA +00 B +00 CC +00 D +00 H +00 II +00 KK +01 LL +01 JJ +01
** {X-AA +00 B +00 H +00 II +00
{X-AA +00 B +00 H +00 II +00 JJ +01 CC +00 D +00
** {X-MM -01
** {X-NN -08

for the ** indicated lines the result would be that all numerical values
match. (And that in turn means that the not-shown section that follows does
not need additional processing)
Post by Walter Pachl
Is this your Input?
Can you show the expected result?
--
Walter
--
Robert AH Prins
***@gmail.com

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Jeremy Nicoll
2015-09-14 21:58:06 UTC
Permalink
Raw Message
Post by Robert Prins
All I need to know is if the numerical values are the same, so
** {X-AA +00 B +00 CC +00 D +00
{X-AA +00 B +00 CC +00 D +00 E +00 FF +01 G +00
{X-AA +00 B +00 CC +00 D +00 H +00 II +00 JJ +01
{X-AA +00 B +00 CC +00 D +00 H +00 II +00 KK +01 LL +01 JJ
+01
** {X-AA +00 B +00 H +00 II +00
{X-AA +00 B +00 H +00 II +00 JJ +01 CC +00 D +00
** {X-MM -01
** {X-NN -08
You could start by chopping off the initial "{X-" and using translate to
change all
the remaining letters to a space, so for example

{X-AA +00 B +00 CC +00 D +00 H +00 II +00 JJ

would become

+00 +00 +00 +00 +00 +00

then parse the first word ie in this case "+00"

then replace all occurrences of that value by space. Then trim
leading/trailing spaces
away. If what you have then is a null string, all the values were the
same. I think.

--
Jeremy Nicoll - my opinions are my own.

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Don Williams
2015-09-14 22:19:56 UTC
Permalink
Raw Message
Not tested, but maybe something like...

If same(input) then ... /* all same */
Else ... /* one different */

Where same function is...

Same: proc
Arg str
Parse var str ignore value0 remain
Exit = 0
Do while exit = 0 & remain <> ""
Parse var remain ignore value1 remain
If value0 <> value1 then exit = 1
End
Return

Minor adjustments needed for comma separators.
Post by Jeremy Nicoll
Post by Robert Prins
All I need to know is if the numerical values are the same, so
** {X-AA +00 B +00 CC +00 D +00
{X-AA +00 B +00 CC +00 D +00 E +00 FF +01 G +00
{X-AA +00 B +00 CC +00 D +00 H +00 II +00 JJ +01
{X-AA +00 B +00 CC +00 D +00 H +00 II +00 KK +01 LL +01 JJ
+01
** {X-AA +00 B +00 H +00 II +00
{X-AA +00 B +00 H +00 II +00 JJ +01 CC +00 D +00
** {X-MM -01
** {X-NN -08
You could start by chopping off the initial "{X-" and using translate to
change all
the remaining letters to a space, so for example
{X-AA +00 B +00 CC +00 D +00 H +00 II +00 JJ
would become
+00 +00 +00 +00 +00 +00
then parse the first word ie in this case "+00"
then replace all occurrences of that value by space. Then trim
leading/trailing spaces
away. If what you have then is a null string, all the values were the
same. I think.
--
Jeremy Nicoll - my opinions are my own.
----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Gerard46
2015-09-15 02:17:02 UTC
Permalink
Raw Message
| ---- Original Message -----
| From: "Don Williams" <***@GMAIL.COM>
| To: <TSO-***@VM.MARIST.EDU>
| Sent: Monday, September 14, 2015 17:19
| Subject: Re: [TSO-REXX] Test for equality of more than one value
|
Post by Don Williams
Not tested, but maybe something like...
If same(input) then ... /* all same */
Else ... /* one different */
Where same function is...
Same: proc
Arg str
Parse var str ignore value0 remain
Exit = 0
Do while exit = 0 & remain <> ""
Parse var remain ignore value1 remain
If value0 <> value1 then exit = 1
End
Return
I would change the "EXIT" variable name to anything else,
maybe to DONE or somesuch.
It looks too much like an EXIT statement when perusing.

Why not remove the ARG STR and the next statement for
just one statement. Since (now) DONE is a boolean value:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
same: procecure; arg . value0 remain
done=0
do while \done & remain \=''
parse var remain . value1 remain
if value0\=value1 then done=1
end /*while ... */
return
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Note that the ARG statement uppercases all the arguments
passed to SAME procedure. Of course, you could
reinsert the IGNORE variable for debugging purposes.
______________________________ Gerard Schildberger

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Brenton, Ren
2015-09-15 11:50:42 UTC
Permalink
Raw Message
How about something like this:

/* REXX */

/* load the stem */

STEM1.1 = '{X-AA +00 B +00 CC +00 D +00'
STEM1.2 = '{X-AA +00 B +00 CC +00 D +00 E +00 FF +01 G +00'
STEM1.3 = '{X-AA +00 B +00 CC +00 D +00 H +00 II +00 JJ +01'
STEM1.4 = '{X-AA +00 B +00 CC +00 D +00 H +00',
'II +00 KK +01 LL +01 JJ +01'
STEM1.5 = '+01AA +00 B +00 CC +00 D +00'
STEM1.6 = '{X-AA +00 B +00 H +00 II +00'
STEM1.7 = '{X-AA +00 B +00 H +00 II +00 JJ +01 CC +00 D +00 '
STEM1.8 = '{X-MM -01 B +00 CC +00 D +00'
STEM1.9 = '{X-NN -08'

/* the following two lines are duplicate of lines 6 and 7 */

STEM1.10 = '{X-AA +00 B +00 H +00 II +00'
STEM1.11 = '{X-AA +00 B +00 H +00 II +00 JJ +01 CC +00 D +00 '

STEM.0 = 11
ASTEM. = 'N'

/* process the stem */

Do i = 1 to STEM.0
xx = STEM1.i
If ASTEM.xx <> 'N';Then do
say i ') Exists at position' ASTEM.xx
End
Else do
Say i ') New'
ASTEM.xx = i
End
End

You can parse the raw data, however you'd like, prior to loading the stem. (That is to say, if you are only interested in the numerics, then parse out the alphas).

Ren Brenton
***@bkfs.com


The information contained in this message is proprietary and/or confidential. If you are not the intended recipient, please: (i) delete the message and all copies; (ii) do not disclose, distribute or use the message in any manner; and (iii) notify the sender immediately. In addition, please be aware that any message addressed to our domain is subject to archiving and review by persons other than the intended recipient. Thank you.
Robin Ryerse
2015-09-14 22:07:13 UTC
Permalink
Raw Message
return allequal(translate(string,left(' ',26),alphabet())

allequal:
do arg# = 2 to words(args())
if arg(arg#) \= arg(1) return 0
end
return 1

alphabet:
return('ABCDEFGHIJKLMNOPQESTUVWXYZ')


-----Original Message-----
From: TSO REXX Discussion List [mailto:TSO-***@VM.MARIST.EDU] On Behalf Of Robert Prins
Sent: September 14, 2015 3:10 PM
To: TSO-***@VM.MARIST.EDU
Subject: [TSO-REXX] Test for equality of more than one value

Hi all,

Can anyone come up with a smart way of telling me if all values in a series are equal? The length of the series ranges from 1 to potentially about 200+ (although in practice the longest series currently counts 15 values)

The format of the series is '{Z-' followed by ID (3 characters)/space/number (sign+2digits)/space sets, so e.g.

{X-AA +00 B +00 CC +00 D +00
{X-AA +00 B +00 CC +00 D +00 E +00 FF +01 G +00
{X-AA +00 B +00 CC +00 D +00 H +00 II +00 JJ +01
{X-AA +00 B +00 CC +00 D +00 H +00 II +00 KK +01 LL +01 JJ +01
{X-AA +00 B +00 H +00 II +00
{X-AA +00 B +00 H +00 II +00 JJ +01 CC +00 D +00
{X-MM -01
{X-NN -08

I need to flag those where the number is not the same for all ID's.

If all values are 00, a simple

if string = translate(string, '000000000', '1234566789') then

works, but it (obviously) fails for cases where all values are the same, but not +00. One added complication is that the space following the number may in future be replaced by a space, or 'a', or 'b', or 'c', or 'd'.

Robert
--
Robert AH Prins
***@gmail.com

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions, send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Gerard46
2015-09-15 02:00:03 UTC
Permalink
Raw Message
|----- Original Message -----
|From: "Robin Ryerse" <***@GMAIL.COM>
|To: <TSO-***@VM.MARIST.EDU>
|Sent: Monday, September 14, 2015 17:07
|Subject: Re: [TSO-REXX] Test for equality of more than one value
|

| return allequal(translate(string,left(' ',26),alphabet())

---snipped---

The left('',26) part can just be omitted entirely:

return allequal( translate(string, , alphabet() )

/*translate all uppercase letters to blanks.*/

_____________________ Gerard Schildberger

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
stonethom
2015-09-15 12:18:51 UTC
Permalink
Raw Message
Gerard, it is good to see your input again on this list.Thom


Sent from my Sprint Samsung Galaxy S® 6.-------- Original message --------
From: Gerard46 <***@RRT.NET>
Date: 09/14/2015 22:25 (GMT-05:00)
To: TSO-***@VM.MARIST.EDU
Subject: Re: [TSO-REXX] Test for equality of more than one value

| ---- Original Message -----
| From: "Don Williams" <***@GMAIL.COM>
| To: <TSO-***@VM.MARIST.EDU>
| Sent: Monday, September 14, 2015 17:19
| Subject: Re: [TSO-REXX] Test for equality of more than one value
|
Post by Don Williams
Not tested, but maybe something like...
If same(input) then ... /* all same */
Else ... /* one different */
Where same function is...
Same: proc
Arg str
Parse var str ignore value0 remain
Exit = 0
Do while exit = 0 & remain <> ""
Parse var remain ignore value1 remain
If value0 <> value1 then exit = 1
End
Return
I would change the "EXIT" variable name to anything else,
maybe to   DONE   or somesuch.
It looks too much like an  EXIT  statement when perusing.

Why not remove the  ARG STR and the next statement for
just one statement.   Since (now)  DONE  is a boolean value:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
same: procecure;  arg . value0 remain
done=0
                do   while \done  & remain \=''
                parse var remain . value1 remain
                if value0\=value1  then done=1
                end   /*while ... */
return
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Note that the   ARG   statement uppercases all the arguments
passed to   SAME  procedure.       Of course,  you could
reinsert the   IGNORE   variable for debugging purposes.
______________________________ Gerard Schildberger

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Bob Bridges
2015-10-24 13:22:26 UTC
Permalink
Raw Message
Haven't been on in a while; I know I'm late. If the '+' and the two digits are to be counted upon, this oughta work; just call it as a Boolean function, supplying it a line at a time:

/* Are all the +nn the same in lin? */
fSameNbr: arg lin
parse var lin '+' v1 +2 lin
do forever
parse var lin '+' nn +2 lin
if nn<>v1 then return 0; end
return 1

---
Bob Bridges
***@gmail.com, cell 336 382-7313
***@InfoSecInc.com

/* Cynicism is the imagination of the mediocre. -Joe Klein, author of _Primary Colors_ */

-----Original Message-----
From: TSO REXX Discussion List [mailto:TSO-***@VM.MARIST.EDU] On Behalf Of Robert Prins
Sent: Monday, September 14, 2015 15:10

Can anyone come up with a smart way of telling me if all values in a series are equal? The length of the series ranges from 1 to potentially about 200+ (although in practice the longest series currently counts 15 values)

The format of the series is '{Z-' followed by ID (3 characters)/space/number (sign+2digits)/space sets, so e.g.

{X-AA +00 B +00 CC +00 D +00
{X-AA +00 B +00 CC +00 D +00 E +00 FF +01 G +00
{X-AA +00 B +00 CC +00 D +00 H +00 II +00 JJ +01
{X-AA +00 B +00 CC +00 D +00 H +00 II +00 KK +01 LL +01 JJ +01
{X-AA +00 B +00 H +00 II +00
{X-AA +00 B +00 H +00 II +00 JJ +01 CC +00 D +00
{X-MM -01
{X-NN -08

I need to flag those where the number is not the same for all ID's.

If all values are 00, a simple

if string = translate(string, '000000000', '1234566789') then

works, but it (obviously) fails for cases where all values are the same, but not +00. One added complication is that the space following the number may in future be replaced by a space, or 'a', or 'b', or 'c', or 'd'.

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Robert Garrett
2015-10-24 16:12:53 UTC
Permalink
Raw Message
Interesting problem!

I thought about iterative PARSE too, but thought I'd try something else. This sample also detects which values are different and handles arbitrary numeric values including those with decimals.
It handles input strings that contain any amount of arbitrary character 'trash' in them, even "unprintable" binary/hex data. Numeric values do not necessarily have to be prefixed with a sign character.

/* This section of code is only needed "once" to initialize the
masks */

/* Build translate masks to help strip all the 'trash' characters
Out of the original value */
_INMASK = COPIES(' ',256); /* 256 spaces */
do X = 1 to 256;
_INMASK = OVERLAY(D2C(X,1),_INMASK,X);
end X;
/* _INMASK is now a 256 byte string that contains all possible
Character codes from '00'x to 'FF'x at their corresponding
"Offsets" into the string */

_OUTMASK = COPIES(' ',256); /* _OUTMASK is 256 spaces */
/* 'Restore' the numeric and sign characters */
do X = 0 to 9;
_OUTMASK = OVERLAY(X,_OUTMASK,C2D(X));
end X;
_OUTMASK = OVERLAY('+',_OUTMASK,C2D('+'));
_OUTMASK = OVERLAY('-',_OUTMASK,C2D('-'));
_OUTMASK = OVERLAY('.',_OUTMASK,C2D('.'));
/* _OUTMASK can now be used in conjunction with _INMASK on
a TRANSLATE function to remove all "unwanted"
characters from a string value */

/* End of "one time" code */

/* Demonstration of use */
.
.
.
_VAR = '{X-AA +00 B +00 CC +00 D +0.1H +00 II +00 KK +00 LL';

/* Strip out 'trash' characters */
_TEST = TRANSLATE(_VAR,_OUTMASK,_INMASK);

/* Remove any "orphan" sign and/or decimal character occurrences */
Do while POS('- ',_TEST) > 0; /* '-' followed by one space */
_TEST = OVERLAY(' ',_TEST,POS('- ',_TEST)); /* replace with 2 spaces */
end;
do while POS('+ ',_TEST) > 0; /* '+' followed by one space */
_TEST = OVERLAY(' ',_TEST,POS('+ ',_TEST)); /* replace with 2 spaces */
end;
do while POS(' . ',_TEST) > 0; /* '.' bounded on both sides by spaces */
_TEST = OVERLAY(' ',_TEST,POS(' . ',_TEST)); /* replace with 3 spaces */
end;
/* The above will not handle all of the boundary conditions where one of these characters is 'orphaned' and appears
At the trailing end of the string (such that it is not followed by one space)
If that situation is possible in the data, then something like
If RIGHT(_TEST,2) = ' -' then,
_TEST = OVERLAY(' ',_TEST,(LENGTH(_TEST) - 1));
If RIGHT(_TEST,2) = ' +' then,
_TEST = OVERLAY(' ',_TEST,(LENGTH(_TEST) - 1));
If RIGHT(_TEST,2) = ' .' then,
_TEST = OVERLAY(' ',_TEST,(LENGTH(_TEST) - 1));
Will handle that case
likewise
If LEFT(_TEST,2) = '. ' then,
_TEST = OVERLAY(' ',_TEST,1);
Will handle cases where a single '.' character appears at the beginning of the string */

/* All of that work set us up to be able to use the WORD and WORDS functions to
Examine all the values */

/* Check all the numeric values in the string */
do X = 1 to WORDS(_TEST);
_CURRVAL = WORD(_TEST,X);
if SYMBOL('_FIRSTVAL') <> 'VAR' then,
_FIRSTVAL = _CURRVAL; /* 'First iteration' logic */
if _FIRSTVAL <> _CURRVAL then,
do;
say 'Value',
X,
'('_CURRVAL')',
'is different from',
_FIRSTVAL;
_DIFFERENT = 1; /* "Remember" we found at least one difference */
end;
/* Note that +00 and -00 will compare as being equal */
end X;
if SYMBOL('_DIFFERENT') <> 'VAR' then,
say 'All values are the same';
.
.
.
.

Output from running this sample should be:
Value 4 (+0.1) is different from +00

Robert


-----Original Message-----
From: TSO REXX Discussion List [mailto:TSO-***@VM.MARIST.EDU] On Behalf Of Robert Prins
Sent: Monday, September 14, 2015 2:10 PM
To: TSO-***@VM.MARIST.EDU
Subject: [TSO-REXX] Test for equality of more than one value

Hi all,

Can anyone come up with a smart way of telling me if all values in a series are equal? The length of the series ranges from 1 to potentially about 200+ (although in practice the longest series currently counts 15 values)

The format of the series is '{Z-' followed by ID (3 characters)/space/number (sign+2digits)/space sets, so e.g.

{X-AA +00 B +00 CC +00 D +00
{X-AA +00 B +00 CC +00 D +00 E +00 FF +01 G +00
{X-AA +00 B +00 CC +00 D +00 H +00 II +00 JJ +01
{X-AA +00 B +00 CC +00 D +00 H +00 II +00 KK +01 LL +01 JJ +01
{X-AA +00 B +00 H +00 II +00
{X-AA +00 B +00 H +00 II +00 JJ +01 CC +00 D +00
{X-MM -01
{X-NN -08

I need to flag those where the number is not the same for all ID's.

If all values are 00, a simple

if string = translate(string, '000000000', '1234566789') then

works, but it (obviously) fails for cases where all values are the same, but not +00. One added complication is that the space following the number may in future be replaced by a space, or 'a', or 'b', or 'c', or 'd'.

Robert
--
Robert AH Prins
***@gmail.com

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions, send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Robert Zenuk
2015-10-24 17:30:56 UTC
Permalink
Raw Message
To make it 4 Roberts in the thread... Here is another approach using MAX and MIN just to determine equivalence.

/* rexx */
v.1 = 'X-AA +00 B +00 CC +00 D +00'
v.2 = 'X-AA +00 B +00 CC +00 D +00 E +00 FF +01 G +00'
v.3 = 'X-AA +00 B +00 CC +00 D +00 H +00 II +00 JJ +01'
v.4 = 'X-AA +00 B +00 CC +00 D +00 H +00 II +00 KK +01 LL +01 JJ +01'
v.5 = 'X-AA +00 B +00 H +00 II +00'
v.6 = 'X-AA +00 B +00 H +00 II +00 JJ +01 CC +00 D +00'
v.7 = 'X-MM -01'
v.8 = 'X-NN -08'
v.0 = 8
do i=1 to v.0
parse var v.i id 5 v.i
v.i = translate(v.i,' ','abcd')
do j=1 to words(v.i)
select
when j = 1 then
do
max = word(v.i,1)
min = word(v.i,1)
end
when j//2 <> 0 then
do
max = max(max,word(v.i,j))
min = min(min,word(v.i,j))
end
otherwise nop
end
end
if max = min then
say id 'SAME' v.i
else
say id 'DIFF' v.i
end

Rob



-----Original Message-----
From: Robert Garrett <***@GARRETTFAMILY.US>
To: TSO-REXX <TSO-***@VM.MARIST.EDU>
Sent: Sat, Oct 24, 2015 9:12 am
Subject: Re: Test for equality of more than one value


Interesting problem!

I thought about iterative PARSE too, but thought I'd try
something else. This sample also detects which values are different and handles
arbitrary numeric values including those with decimals.
It handles input
strings that contain any amount of arbitrary character 'trash' in them, even
"unprintable" binary/hex data. Numeric values do not necessarily have to be
prefixed with a sign character.

/* This section of code is only needed "once"
to initialize the
masks */

/* Build translate masks to help strip all
the 'trash' characters
Out of the original value */
_INMASK = COPIES('
',256); /* 256 spaces */
do X = 1 to 256;
_INMASK =
OVERLAY(D2C(X,1),_INMASK,X);
end X;
/* _INMASK is now a 256 byte string that
contains all possible
Character codes from '00'x to 'FF'x at their
corresponding
"Offsets" into the string */

_OUTMASK = COPIES(' ',256); /*
_OUTMASK is 256 spaces */
/* 'Restore' the numeric and sign characters */
do
X = 0 to 9;
_OUTMASK = OVERLAY(X,_OUTMASK,C2D(X));
end X;
_OUTMASK =
OVERLAY('+',_OUTMASK,C2D('+'));
_OUTMASK = OVERLAY('-',_OUTMASK,C2D('-'));

_OUTMASK = OVERLAY('.',_OUTMASK,C2D('.'));
/* _OUTMASK can now be used in
conjunction with _INMASK on
a TRANSLATE function to remove all "unwanted"

characters from a string value */

/* End of "one time" code */

/*
Demonstration of use */
.
.
.
_VAR = '{X-AA +00 B +00 CC +00 D +0.1H
+00 II +00 KK +00 LL';

/* Strip out 'trash' characters */
_TEST =
TRANSLATE(_VAR,_OUTMASK,_INMASK);

/* Remove any "orphan" sign and/or decimal
character occurrences */
Do while POS('- ',_TEST) > 0; /* '-' followed by one
space */
_TEST = OVERLAY(' ',_TEST,POS('- ',_TEST)); /* replace with 2
spaces */
end;
do while POS('+ ',_TEST) > 0; /* '+' followed by one space
*/
_TEST = OVERLAY(' ',_TEST,POS('+ ',_TEST)); /* replace with 2 spaces
*/
end;
do while POS(' . ',_TEST) > 0; /* '.' bounded on both sides by spaces
*/
_TEST = OVERLAY(' ',_TEST,POS(' . ',_TEST)); /* replace with 3 spaces
*/
end;
/* The above will not handle all of the boundary conditions where one
of these characters is 'orphaned' and appears
At the trailing end of the
string (such that it is not followed by one space)
If that situation is
possible in the data, then something like
If RIGHT(_TEST,2) = ' -' then,

_TEST = OVERLAY(' ',_TEST,(LENGTH(_TEST) - 1));
If RIGHT(_TEST,2) = ' +'
then,
_TEST = OVERLAY(' ',_TEST,(LENGTH(_TEST) - 1));
If
RIGHT(_TEST,2) = ' .' then,
_TEST = OVERLAY(' ',_TEST,(LENGTH(_TEST)
- 1));
Will handle that case
likewise
If LEFT(_TEST,2) = '. '
then,
_TEST = OVERLAY(' ',_TEST,1);
Will handle cases where a
single '.' character appears at the beginning of the string */

/* All of that
work set us up to be able to use the WORD and WORDS functions to
Examine
all the values */

/* Check all the numeric values in the string */
do X = 1
to WORDS(_TEST);
_CURRVAL = WORD(_TEST,X);
if SYMBOL('_FIRSTVAL') <>
'VAR' then,
_FIRSTVAL = _CURRVAL; /* 'First iteration' logic */

if _FIRSTVAL <> _CURRVAL then,
do;
say 'Value',

X,
'('_CURRVAL')',
'is different
from',
_FIRSTVAL;
_DIFFERENT = 1; /*
"Remember" we found at least one difference */
end;
/* Note that +00
and -00 will compare as being equal */
end X;
if
SYMBOL('_DIFFERENT') <> 'VAR' then,
say 'All values are the
same';
.
.
.
.

Output from running this sample should be:
Value 4
(+0.1) is different from +00

Robert


-----Original Message-----
From:
TSO REXX Discussion List [mailto:TSO-***@VM.MARIST.EDU] On Behalf Of Robert
Prins
Sent: Monday, September 14, 2015 2:10 PM
To:
TSO-***@VM.MARIST.EDU
Subject: [TSO-REXX] Test for equality of more than one
value

Hi all,

Can anyone come up with a smart way of telling me if all
values in a series are equal? The length of the series ranges from 1 to
potentially about 200+ (although in practice the longest series currently counts
15 values)

The format of the series is '{Z-' followed by ID (3
characters)/space/number (sign+2digits)/space sets, so e.g.

{X-AA +00 B
+00 CC +00 D +00
{X-AA +00 B +00 CC +00 D +00 E +00 FF +01 G
+00
{X-AA +00 B +00 CC +00 D +00 H +00 II +00 JJ +01
{X-AA +00 B
+00 CC +00 D +00 H +00 II +00 KK +01 LL +01 JJ +01
{X-AA +00 B +00
H +00 II +00
{X-AA +00 B +00 H +00 II +00 JJ +01 CC +00 D
+00
{X-MM -01
{X-NN -08

I need to flag those where the number is not the
same for all ID's.

If all values are 00, a simple

if string =
translate(string, '000000000', '1234566789') then

works, but it (obviously)
fails for cases where all values are the same, but not +00. One added
complication is that the space following the number may in future be replaced by
a space, or 'a', or 'b', or 'c', or 'd'.

Robert
--
Robert AH
Prins
***@gmail.com

----------------------------------------------------------------------
For
TSO-REXX subscribe / signoff / archive access instructions, send email to
***@VM.MARIST.EDU with the message: INFO
TSO-REXX

----------------------------------------------------------------------
For
TSO-REXX subscribe / signoff / archive access instructions,
send email to
***@VM.MARIST.EDU with the message: INFO TSO-REXX



----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Loading...