delete duplicate brand names in the concatenated variable

classic Classic list List threaded Threaded
33 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: delete duplicate brand names in the concatenated variable

David Marso
Administrator
IF INDEX(!X,CONCAT(valuelabels(var),';')) EQ 0  and char.length(RTRIM(valuelabels(var))) gt 0 !X = CONCAT(!X,valuelabels(var),";").
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: delete duplicate brand names in the concatenated variable

David Marso
Administrator
Oops:
Should be:
IF INDEX(!X,CONCAT(valuelabels(var),';')) EQ 0  and char.length(valuelabels(var)) gt 0 !X = CONCAT(RTRIM(!X),valuelabels(var),";").


David Marso wrote
IF INDEX(!X,CONCAT(valuelabels(var),';')) EQ 0  and char.length(RTRIM(valuelabels(var))) gt 0 !X = CONCAT(!X,valuelabels(var),";").
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: delete duplicate brand names in the concatenated variable

jagadishpchary
Hi David:

I tried your syntax but still no luck..
Reply | Threaded
Open this post in threaded view
|

Re: delete duplicate brand names in the concatenated variable

David Marso
Administrator
LUCK has nothing to do with it.
Please post EXACTLY what you ran using the mock up you provided earlier along with the macros and macro call.
Perhaps you should read the documentation to become familiar with what each of the functions does.
IF (blah blah) !X=CONCAT(RTRIM(!X),";",blah).

jagadishpchary wrote
Hi David:

I tried your syntax but still no luck..
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: delete duplicate brand names in the concatenated variable

jagadishpchary
Below is the code I am running - However the 'SOCLAS' data is not concatenated in the final varibale "TEST"

DEFINE MRMAC (START = !CHAREND("/") / END = !CHAREND("/") / X = !TOKENS(1) /nbval=!TOKENS(1)).
string !X(a2500).
do repeat var = !START to !END.
IF INDEX(!X,CONCAT(valuelabels(var),';')) EQ 0  and char.length(valuelabels(var)) gt 0 !X = CONCAT(RTRIM(!X),valuelabels(var),";").
end repeat.
COMPUTE !X = RTRIM(!X,";").
!ENDDEFINE.

MRMAC START = AGE / END = SOCLAS / X = TEST.
EXECUTE.
Reply | Threaded
Open this post in threaded view
|

Re: delete duplicate brand names in the concatenated variable

David Marso
Administrator
It is incredibly obvious but I'm not telling!!!
Look at your labels, look at the code.
Give yourself a solid tap with the clue stick!
---
jagadishpchary wrote
Below is the code I am running - However the 'SOCLAS' data is not concatenated in the final varibale "TEST"

DEFINE MRMAC (START = !CHAREND("/") / END = !CHAREND("/") / X = !TOKENS(1) /nbval=!TOKENS(1)).
string !X(a2500).
do repeat var = !START to !END.
IF INDEX(!X,CONCAT(valuelabels(var),';')) EQ 0  and char.length(valuelabels(var)) gt 0 !X = CONCAT(RTRIM(!X),valuelabels(var),";").
end repeat.
COMPUTE !X = RTRIM(!X,";").
!ENDDEFINE.

MRMAC START = AGE / END = SOCLAS / X = TEST.
EXECUTE.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: delete duplicate brand names in the concatenated variable

jagadishpchary
I agree that I need to read the manual before posting this query. Since, I am new to SPSS it might be hard for me to resolve this issue. Hence, if you have the solution please let me know.
Reply | Threaded
Open this post in threaded view
|

Re: delete duplicate brand names in the concatenated variable

David Marso
Administrator
Like I said, Look at your labels for SOCLAS and consider why they would be excluded!
I won't drop a fish on your plate because you have changed the context of the question and the code that worked for the original is not necessarily applicable in entirety.
I think the code is simple enough that you can chew on the details and acquire something of an epiphany while you ponder that copy/paste without critical reflection is bound to bite you in the posterior.

jagadishpchary wrote
I agree that I need to read the manual before posting this query. Since, I am new to SPSS it might be hard for me to resolve this issue. Hence, if you have the solution please let me know.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: delete duplicate brand names in the concatenated variable

David Marso
Administrator
Also, you initiated the original thread about a month and a half ago with a macro you obviously cribbed from somebody else.  I believe you have had ample time to acquaint yourself with CONCAT and RTRIM!!!  This is not the place to be spoon fed with minutia you are too lazy to attempt to grok.
Over and Out!
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: delete duplicate brand names in the concatenated variable

jagadishpchary

Hope this forum is meant to provide an answer but not to criticize anyone.
If you think my question is crazy - then please don't answer it. but don't advice me on how should I be. Going forward don't teach any lessons to anyone. if you know the answer then post it else ignore it.
Reply | Threaded
Open this post in threaded view
|

Re: delete duplicate brand names in the concatenated variable

David Marso
Administrator
I told you what to look for!!!
LIST the result of what you end up with.
Look at the Labels for the SOSCLAS variable.
Look up the INDEX function in the FM (Fine Manual) ie. RTFM!!!
What do you think it is doing?
Hmm, maybe that IF statement is hosing things up?
Yeah, I'm going Socratic on your lazy butt!
If anybody drops a fish on your plate they are encouraging you to be lazy.
You are being paid to do your job after all?  Step up to the plate!
--
jagadishpchary wrote
Hope this forum is meant to provide an answer but not to criticize anyone.
If you think my question is crazy - then please don't answer it. but don't advice me on how should I be. Going forward don't teach any lessons to anyone. if you know the answer then post it else ignore it.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: delete duplicate brand names in the concatenated variable

David Marso
Administrator
In reply to this post by jagadishpchary

OOPS!  Looks like you got your butt bitten by a bug!
I never realized that using END as a parameter name in macro caused bad things to happen ;-(
Hope this helps.  Have a great weekend.

DEFINE !x (FIRST !TOKENS(1) /END !TOKENS(1) )
DO REPEAT v=!FIRST TO !END .
END REPEAT .
!ENDDEFINE.
SET MPRINT ON.
!x FIRST = a END=b .

1024  0 M>  DO REPEAT v= a TO b b.

*---------------------------------------------------------------- .

DEFINE MRMAC (First !TOKENS(1) / Last !TOKENS(1) / X = !TOKENS(1) ).
STRING !X(A2500).
DO REPEAT var = !First to !Last.
COMPUTE  !X = CONCAT(RTRIM(!X),valuelabels(var),";").
END REPEAT.
COMPUTE !X = CHAR.SUBSTR(!X,1,RINDEX(!X,";")-1).
!ENDDEFINE.

DATA LIST LIST  / AGE SEX JOBR LOCAT SOCLAS.
BEGIN DATA.
1,2,1,1,2
5,2,3,2,1
3,2,2,2,2
5,2,4,2,2
5,1,3,2,2
END DATA.

VALUE LABELS
 /  AGE   1 "18-24"  2 "25-34"  3 "35-44"  4 "45-54"  5 "55-64"
 /  SEX   1 "MALE" 2 "FEMALE"
 /  JOBR 1 "FULL TIME EDUCATION"  2 "PART TIME"  3 "RETIRED"  4 "NOT WORKING"
 / LOCAT  1 "RURAL"  2 "URBAN"
 / SOCLAS  1 "D"  2 "E".

SET MPRINT ON.
MRMAC FIRST= AGE  LAST = SOCLAS  X = TEST.
LIST.

 
 
The variables are listed in the following order:
 
LINE   1: AGE SEX JOBR LOCAT SOCLAS
 
LINE   2: TEST
 
 
 
 
         AGE:     1.00     2.00     1.00     1.00     2.00
        TEST: 18-24;FEMALE;FULL TIME EDUCATION;RURAL;E
 
         AGE:     5.00     2.00     3.00     2.00     1.00
        TEST: 55-64;FEMALE;RETIRED;URBAN;D
 
         AGE:     3.00     2.00     2.00     2.00     2.00
        TEST: 35-44;FEMALE;PART TIME;URBAN;E
 
         AGE:     5.00     2.00     4.00     2.00     2.00
        TEST: 55-64;FEMALE;NOT WORKING;URBAN;E
 
         AGE:     5.00     1.00     3.00     2.00     2.00
        TEST: 55-64;MALE;RETIRED;URBAN;E
 
 
Number of cases read:  5    Number of cases listed:  5

jagadishpchary wrote
Hope this forum is meant to provide an answer but not to criticize anyone.
If you think my question is crazy - then please don't answer it. but don't advice me on how should I be. Going forward don't teach any lessons to anyone. if you know the answer then post it else ignore it.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: delete duplicate brand names in the concatenated variable

jagadishpchary
David. thanks for the code.
12