Value label Macro

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

Value label Macro

Ujjawal
Hey SPSS Gurus,

I wish to automate value labeling for a string variable. The variable contains 20-30 values.

Example :

VALUE LABELS Categories
'RA_2' "Category/123"
'RA_3' "Category555"
'RA_4' "Category125".

Can we accomplish this using DEFINE - !ENDDEFINE?
Something like this :
DEFINE Options ( ) RA_2 RA_3 RA_4 !ENDDEFINE.
DEFINE LAB ( ) 'Category/123' 'Category 555' 'Category 125' !ENDDEFINE.

VALUE LABELS Categories
!quote(Options) !quote(LAB).


 
Reply | Threaded
Open this post in threaded view
|

Re: Value label Macro

David Marso
Administrator
This post was updated on .
Being one of the resident experts on MACRO I don't see where this provides any advantage whatsoever beyond simply writing out the RECODE command.  After all you will end up likely having to build out just as much explicit specifications on any such invocation as the RECODE and it will be a monster to maintain.
Your successor (if any) in maintaining such a beast would justifiably hunt you down and subject you to the unthinkable  (Jack Bauer comes to mind).
Maybe you have a good reason for this but what you have described does not provide adequate context to provide further guidance.

Note  !QUOTE cannot be used outside of DEFINE !ENDDEFINE so you would have to wrap that last piece inside another macro .  Also, that expansion is surely NOT what you would want anyway.
If in doubt just try it and see what silliness transpires.
Since you have yet to completely damage your brain with that crippled beast MACRO you might do better to invest your time mastering Python (I'll bet Jon just spit coffee on his monitor reading this from me ;-).

Now, I started using and supporting Macros (SPSS Technical Support) back around 1991 so I am already  more or less FUBAR .    It is not too late for you to turn back and reconsider!.

Not too late for me to adopt python (which I shall very soon  But you'll have to pry macro from my cold dead hands for some things ).

However, just to give you an sense of the hideous, brain damaging type of thing you will be avoiding by turning your back on MACRO (for this sort of thing) and venturing into the land of the snake-heads.  

I proffer the following answer to your sort of question and ask:  
DO YOU REALLY WANT TO GO THERE? ;-)))
---
DEFINE Options ( ) RA_2 RA_3 RA_4 !ENDDEFINE.
DEFINE LAB ( ) 'Category/123' 'Category 555' 'Category 125' !ENDDEFINE.

DEFINE AbandonAllHopeYeWhoEnterHere( VAR !TOKENS(1)).
!LET !X=!EVAL(LAB)
VALUE LABELS !VAR
!DO !XV !IN ( !EVAL(Options))!LET !XL=!HEAD(!X)!CONCAT(!QUOTE(!XV)," ",!XL)
!LET !X=!TAIL(!X)!DOEND
*WAS* !LET !XL=!TAIL(!XL)!DOEND
!ENDDEFINE.

** GAG ME WITH A SHARP STICK **.

SET MPRINT ON.
DATA LIST FREE / Categories (A4).
BEGIN DATA
RA_2
RA_3
RA_4
END DATA.

AbandonAllHopeYeWhoEnterHere VAR Categories .

  89  0 M>  
AbandonAllHopeYeWhoEnterHere VAR Categories .
  90  0 M>  
  91  0 M>  .
  92  0 M>  VALUE LABELS Categories 'RA_2' 'Category/123' 'RA_3' 'Category/123' 'RA_4' 'Category/123'
  93  0 M>  .

I FEEL DIRTY, CORRUPTING THE YOUTH!~
Shame on me ;-)))
---
Ujjawal wrote
Hey SPSS Gurus,

I wish to automate value labeling for a string variable. The variable contains 20-30 values.

Example :

VALUE LABELS Categories
'RA_2' "Category/123"
'RA_3' "Category555"
'RA_4' "Category125".

Can we accomplish this using DEFINE - !ENDDEFINE?
Something like this :
DEFINE Options ( ) RA_2 RA_3 RA_4 !ENDDEFINE.
DEFINE LAB ( ) 'Category/123' 'Category 555' 'Category 125' !ENDDEFINE.

VALUE LABELS Categories
!quote(Options) !quote(LAB).
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: Value label Macro

Jon K Peck


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
phone: 720-342-5621




From:        David Marso <[hidden email]>
To:        [hidden email],
Date:        03/20/2013 10:33 AM
Subject:        Re: [SPSSX-L] Value label Macro
Sent by:        "SPSSX(r) Discussion" <[hidden email]>



[snip]

Since you have yet to completely damage your brain with that crippled beast
MACRO you might do better to invest your time mastering Python (I'll bet Jon
just spit coffee on his monitor reading this from me ;-).


>>>gasp!  Reaching for paper towels.

Now, I started using and supporting Macros (SPSS Technical Support) back
around 1991 so I am already  more or less FUBAR .    It is not too late for
you to turn back and reconsider!.

Not too late for me to adopt python (which I shall very soon  But you'll
have to pry macro from my cold dead hands for some things ).


>>>You will especially like the Python api that generates a macro definition.  I actually use that regularly to generate lists of variables that meet certain criteria.  In one recent use, I needed to generate an expression for the variables created by CASESTOVARS.  I also used this in creating the SPSSINC SELECT VARIABLES extension command.  That command allows you to select a subset of the variables in a dataset based on patterns in the names, type, measurement level, role, and custom attributes and creates a macro listing those variables.  This is useful in generalizing syntax files so that they are less dependent on particular variable names and thus more reusable.  Here is an example.

SPSSINC SELECT VARIABLES MACRONAME="!continuous"
/PROPERTIES LEVEL=SCALE.
DESCRIPTIVES !continuous.

And, yes, if there are no continuous variables, the SELECT command can throw an error.



=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD


Reply | Threaded
Open this post in threaded view
|

Re: Value label Macro

Ujjawal
In reply to this post by David Marso
Thanks a million David. This code looks so beautiful that my brain fell in love with her :))
The only problem with this code is that it labels same text for every value of a variable.

VALUE LABELS Categories 'RA_2' 'Category/123' 'RA_3' 'Category/123' 'RA_4' 'Category/123'

Today i spent an hour understanding the logic behind it. I thought to debug the code myself.
But as usual fails to crack it :((  I put DO IN loop for labeling but it didn't work.

Reply | Threaded
Open this post in threaded view
|

Re: Value label Macro

David Marso
Administrator
My Bad: Cranial Flatulence on my end ;-).
--
!LET !XL=!HEAD(!X)!CONCAT(!QUOTE(!XV)," ",!XL)!LET !X=!TAIL(!X)!DOEND
was !LET !XL=!TAIL(!XL)

Ujjawal wrote
Thanks a million David. This code looks so beautiful that my brain fell in love with her :))
The only problem with this code is that it labels same text for every value of a variable.

VALUE LABELS Categories 'RA_2' 'Category/123' 'RA_3' 'Category/123' 'RA_4' 'Category/123'

Today i spent an hour understanding the logic behind it. I thought to debug the code myself.
But as usual fails to crack it :((  I put DO IN loop for labeling but it didn't work.
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: Value label Macro

Ujjawal
This post was updated on .
Oops..That was so simple..
That's why the program was returning the same output without using the following statement :
!LET !XL=!TAIL(!XL)

I was concentrating on the following code:
!LET !XL=!HEAD(!X)!CONCAT(!QUOTE
(!XV)," ",!XL)

Shame on my analytical mind!
Reply | Threaded
Open this post in threaded view
|

Re: Value label Macro

David Marso
Administrator
!HEAD takes the first element !TAIL takes everything else.
This enables a parallel traversing of the two lists.

Ujjawal wrote
Oops..That was so simple..
That's why the program was returning the same output without using the following statement :
!LET !XL=!TAIL(!XL)

I was concentrating on the following code:
!LET !XL=!HEAD(!X)!CONCAT(!QUOTE
(!XV)," ",!XL)

Shame on my analytical mind!
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: Value label Macro

Art Kendall
In reply to this post by Ujjawal
I'm not sure what you want to do.
See if AUTORECODE would help.

Art Kendall
Social Research Consultants
On 3/20/2013 10:26 AM, Ujjawal [via SPSSX Discussion] wrote:
Hey SPSS Gurus,

I wish to automate value labeling for a string variable. The variable contains 20-30 values.

Example :

VALUE LABELS Categories
'RA_2' "Category/123"
'RA_3' "Category555"
'RA_4' "Category125".

Can we accomplish this using DEFINE - !ENDDEFINE?
Something like this :
DEFINE Options ( ) RA_2 RA_3 RA_4 !ENDDEFINE.
DEFINE LAB ( ) 'Category/123' 'Category 555' 'Category 125' !ENDDEFINE.

VALUE LABELS Categories
!quote(Options) !quote(LAB).


 


If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/Value-label-Macro-tp5718912.html
To start a new topic under SPSSX Discussion, email [hidden email]
To unsubscribe from SPSSX Discussion, click here.
NAML

Art Kendall
Social Research Consultants