I am trying to find an efficient way for converting yes/no to 1/0 in Excel. Since I am doing the data analyzing at SPSS. Or if there is a way converting YES/NO to 1/0 in SPSS directly?
6 Answers
Try this syntax in SPSS:
This will create a new field with 1 and 0. Also keep in mind that it's case sensitive.
numeric boolFieldName(f1).
recode ynFieldName ("YES" = 1) ("NO" = 0) into boolFieldName.
execute.
-
Thank you very much. Also do you know how can I convert date from Excel to SPSS? My data in Excel was like :"12:00am", but I put into SPSS, it shows like "35088:00:00.00", I checked the variable, the formate shows this is a data variable. Commented Oct 27, 2013 at 16:03
-
This is fine, but since it is only one condition you could also use something like
COMPUTE boolFieldName = (ynFieldName EQ "YES).
Also there is no need to directly declare the field first using numeric, it will be created automatically when using recode into. (All the command does here is to set the fields format to F1.0 as opposed to whatever the default is.)– Andy WCommented Oct 27, 2013 at 23:19
If a cell contains yes or no (say cell A1) then in another cell enter:
=IF(A1="yes",1,0)
Add the below formula in the "Format, Custom". This will replace a 1
with "Yes"
and 0
with "No"
"Yes"_)_%;"ERROR"_)_%;"No"_)_%;"ERROR"_)_%
-
Congrats It works!!! But not accept typing "Yes" or "No". I would like to modify it to accept the typing "Yes" or "No", convert to numbers, but still display "Yes" or "No". Is it possible? Commented Sep 2, 2016 at 18:05
In Excel just use Ctr-H (find and replace). Search for Yes replace all with 1 and opposite for No. Simple :)
Normally SPSS automatically converts Excel date/time values into SPSS data values. The number you report is the raw Excel date value, i.e., it was not converted. This is most likely due to the column containing some values that are not dates or times, so SPSS treats it as a plain numeric field. Look at the problematic column to see if you can spot such entries.