recode positive integer values to successive integer values &leave negative values alone

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

recode positive integer values to successive integer values &leave negative values alone

Art Kendall
I started with string variables with mixed spellings, casing, and languages.
I now have values with gaps in sequential values.  However, I would like to
preserve negative values with specific missing value labels.
A tedious and error-prone way to clean this up would be the syntax below.
I have attached a SAV file with an example variable. crop01.sav
<http://spssx-discussion.1045642.n5.nabble.com/file/t47554/crop01.sav>  

Am I missing a less messy way to do this?

* Encoding: UTF-8.
* change the FILE HANDLE to wherever you put the data.
FILE HANDLE WhereData /NAME='C:\ something'.
GET FILE='WhereData\crop01.sav'.
DATASET NAME Crop WINDOW=FRONT.
* this produces missing values at the high end of the sequence.
AUTORECODE VARIABLES = Crop01 /INTO Show/print.
*  tedious way to get there.
*   add prefix to label of missing values.
ADD VALUE LABELS Crop01
-1 'ZZZ1Missing unknown reason'
-2 'ZZZ2Missing  all HH this Place & Phase'
-3 'ZZZ3Entry or coding error'.
* change to a string variable.
STRING MyTempVar (A100).
COMPUTE MyTempVar= ValueLabel(Crop01).
AUTORECODE VARIABLES = MyTempVar /INTO TempCrop01 /PRINT.
DELETE VARIABLES Crop01.
RENAME VARIABLES (TempCrop01 = Crop01).
* recode input values specific to variable.
RECODE Crop01 (27=-1) (28=-2) (29=-3) (ELSE=COPY).
ADD VALUE LABELS Crop01
-1 'Missing unknown reason'
-2 'Missing  all HH this Place & Phase'
-3 'Entry or coding error'.
FREQUENCIES VARIABLES = Crop01 /MISSING = INCLUDE.





-----
Art Kendall
Social Research Consultants
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: recode positive integer values to successive integer values &leave negative values alone

Jon Peck
AUTORECODE is rather stubborn about how it treats missing values, and even using a template with it to preserve the negative values doesn't work.

But this code would get around that problem.
temporary.
select if not missing(Crop01).
missing values crop01 ().
AUTORECODE VARIABLES=Crop01
  /INTO recoded.
if missing(Crop01) recoded = value(Crop01).
APPLY DICTIONARY
  /FROM *
  /SOURCE VARIABLES=Crop01
  /TARGET VARIABLES=recoded
  /VARINFO MISSING.

On Fri, Aug 28, 2020 at 11:03 AM Art Kendall <[hidden email]> wrote:
I started with string variables with mixed spellings, casing, and languages.
I now have values with gaps in sequential values.  However, I would like to
preserve negative values with specific missing value labels.
A tedious and error-prone way to clean this up would be the syntax below.
I have attached a SAV file with an example variable. crop01.sav
<http://spssx-discussion.1045642.n5.nabble.com/file/t47554/crop01.sav

Am I missing a less messy way to do this?

* Encoding: UTF-8.
* change the FILE HANDLE to wherever you put the data.
FILE HANDLE WhereData /NAME='C:\ something'.
GET FILE='WhereData\crop01.sav'.
DATASET NAME Crop WINDOW=FRONT.
* this produces missing values at the high end of the sequence.
AUTORECODE VARIABLES = Crop01 /INTO Show/print.
*  tedious way to get there.
*   add prefix to label of missing values.
ADD VALUE LABELS Crop01
-1 'ZZZ1Missing unknown reason'
-2 'ZZZ2Missing  all HH this Place & Phase'
-3 'ZZZ3Entry or coding error'.
* change to a string variable.
STRING MyTempVar (A100).
COMPUTE MyTempVar= ValueLabel(Crop01).
AUTORECODE VARIABLES = MyTempVar /INTO TempCrop01 /PRINT.
DELETE VARIABLES Crop01.
RENAME VARIABLES (TempCrop01 = Crop01).
* recode input values specific to variable.
RECODE Crop01 (27=-1) (28=-2) (29=-3) (ELSE=COPY).
ADD VALUE LABELS Crop01
-1 'Missing unknown reason'
-2 'Missing  all HH this Place & Phase'
-3 'Entry or coding error'.
FREQUENCIES VARIABLES = Crop01 /MISSING = INCLUDE.





-----
Art Kendall
Social Research Consultants
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
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


--
Jon K Peck
[hidden email]

===================== 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: recode positive integer values to successive integer values &leave negative values alone

Art Kendall
With dropping the command that removes missing values makes it work like the
syntax below.
*missing values crop01 ().
The file uploaded with the original message is needed to run the syntax.

* Encoding: UTF-8.

FILE HANDLE WhereData /NAME='C:\ someplace'.
GET FILE='WhereData\crop01.sav'.
DATASET NAME Crop WINDOW=ASIS.
temporary.
select if not missing(Crop01).
*missing values crop01 ().
AUTORECODE VARIABLES=Crop01
  /INTO recoded.
EXECUTE.
if missing(Crop01) recoded = value(Crop01).
* Does not carry over labels for missing values.
APPLY DICTIONARY
  /FROM *
  /SOURCE VARIABLES=Crop01
  /TARGET VARIABLES=recoded
  /VARINFO MISSING.

FREQUENCIES VARIABLES =recoded  .
DELETE VARIABLES Crop01.
RENAME VARIABLES (recoded = Crop01).
DD VALUE LABELS Crop01
-1 'Missing unknown reason'
-2 'Missing  all HH this Place & Phase'
-3 'Entry or coding error'.





-----
Art Kendall
Social Research Consultants
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: recode positive integer values to successive integer values &leave negative values alonenm

Prof. Luciano Basso - EEFE USP


Prof. Luciano Basso

Em sáb, 29 de ago de 2020 14:25, Art Kendall <[hidden email]> escreveu:
With dropping the command that removes missing values makes it work like the
syntax below.
*missing values crop01 ().
The file uploaded with the original message is needed to run the syntax.

* Encoding: UTF-8.

FILE HANDLE WhereData /NAME='C:\ someplace'.
GET FILE='WhereData\crop01.sav'.
DATASET NAME Crop WINDOW=ASIS.
temporary.
select if not missing(Crop01).
*missing values crop01 ().
AUTORECODE VARIABLES=Crop01
  /INTO recoded.
EXECUTE.
if missing(Crop01) recoded = value(Crop01).
* Does not carry over labels for missing values.
APPLY DICTIONARY
  /FROM *
  /SOURCE VARIABLES=Crop01
  /TARGET VARIABLES=recoded
  /VARINFO MISSING.

FREQUENCIES VARIABLES =recoded  .
DELETE VARIABLES Crop01.
RENAME VARIABLES (recoded = Crop01).
DD VALUE LABELS Crop01
-1 'Missing unknown reason'
-2 'Missing  all HH this Place & Phase'
-3 'Entry or coding error'.





-----
Art Kendall
Social Research Consultants
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
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
===================== 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