Remove Duplicate values in a variable

 
Parents
  • There are two ways to do this:

    1) Store all your values in an Array, and remove duplicates from this Array with ".unique()" method:


    !data = ARRAY()
    var !coll COLL all ATTA with matchwild(NAME,'*SST*') FOR $!REF

    Do !i index !coll
    !heis = NAME OF $!coll[$!i]
    If !heis.matchwild('*/*') Then
    !firstPart = !heis.before('/')
    Elseif !heis.matchwild('*.*') Then
    !firstPart = !heis.before('.')
    Else
    !firstPart = !heis
    Endif
    [COLOR=#3E3E3E]!data.append(!firstPart)
    Enddo

    !data.unique()

    q var !data
    [/COLOR]


    2) Add the value if it has never been found:


    !data= ARRAY()
    var !coll COLL all ATTA with matchwild(NAME,'*SST*') FOR $!REF

    Do !i index !coll
    !heis = NAME OF $!coll[$!i]
    If !heis.matchwild('*/*') Then
    !firstPart = !heis.before('/')
    Elseif !heis.matchwild('*.*') Then
    !firstPart = !heis.before('.')
    Else
    !firstPart = !heis
    Endif

    If !
    data.findfirst(!firstPart).unset() Then
    !data.append(!firstpart)
    Endif
    [COLOR=#3E3E3E]
    Enddo

    q var !data

    [/COLOR]
Reply
  • There are two ways to do this:

    1) Store all your values in an Array, and remove duplicates from this Array with ".unique()" method:


    !data = ARRAY()
    var !coll COLL all ATTA with matchwild(NAME,'*SST*') FOR $!REF

    Do !i index !coll
    !heis = NAME OF $!coll[$!i]
    If !heis.matchwild('*/*') Then
    !firstPart = !heis.before('/')
    Elseif !heis.matchwild('*.*') Then
    !firstPart = !heis.before('.')
    Else
    !firstPart = !heis
    Endif
    [COLOR=#3E3E3E]!data.append(!firstPart)
    Enddo

    !data.unique()

    q var !data
    [/COLOR]


    2) Add the value if it has never been found:


    !data= ARRAY()
    var !coll COLL all ATTA with matchwild(NAME,'*SST*') FOR $!REF

    Do !i index !coll
    !heis = NAME OF $!coll[$!i]
    If !heis.matchwild('*/*') Then
    !firstPart = !heis.before('/')
    Elseif !heis.matchwild('*.*') Then
    !firstPart = !heis.before('.')
    Else
    !firstPart = !heis
    Endif

    If !
    data.findfirst(!firstPart).unset() Then
    !data.append(!firstpart)
    Endif
    [COLOR=#3E3E3E]
    Enddo

    q var !data

    [/COLOR]
Children
No Data