Let us address first your second question -- converting pay from string to
numeric, and clarifying about decimal formats.
You convert it into a different variable, which will be numeric, with the
RECODE PAYA (convert) into NUMPAY.
If your PAYB variable is also coded as a string, you may want to convert it
RECODE PAYB (CONVERT) INTO NUMDK.
Regarding formats: they only affect the visualization on screen and printed
output, not the internal precision of the figure which is always kept at its
maximum for SPSS, i.e. 16 decimal places. If you want the values of NUMPAY
to display two decimals, add the following:
FORMAT NUMPAY (F10.2).
If you want the dollar sign included, replace (F10.2 by DOLLAR10.2). The
number 10 refers to the total number of places in the visible display,
including the integer and decimal parts, the decimal point and the dollar
sign (and may include also the negative sign, which in your case would not
be present). Thus 50000 dollars would be viewed as $50,000.00 occupying 10
spaces. If needed, e.g. if somebody earns six-figure incomes, increase it to
11 or 12 for good measure. The final 2 refers to the number of decimals. But
I repeat this is only for show: the number itself is not changed by all this
Now for your problem with the DK/NA. Once NUMPAY is created, you may assign
the corresponding values with IF statements as you seem to know how. For
IF (NUMPAY=0 OR SYSMIS(NUMPAY))NUMPAY=NUMDK.
If the values of NUMDK (i.e. the values of your old PAYB) are likely to be
confused with actual salaries when put into NUMPAY, i.e. confusing the code
9997 with a salary of $
9997.00, then you may want to multiply them by 1000 or something similar.
IF (NUMPAY=0 OR SYSMIS(NUMPAY))NUMPAY=NUMDK*1000.
You may want to add some useful labels for the sake of clarity, such as:
ADD VALUE LABELS NUMPAY 9997 'Does not know' 9998 'Does not answer' 9999
Hope this helps
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU]
> On Behalf Of Samantha
> Sent: Sunday, July 24, 2005 3:39 PM
> To: SPSSX-L@LISTSERV.UGA.EDU
> Subject: Need to merge two variables into one based on a condition
> I have a question in my survey that asks how much a person
> earns per hour and also gives them the option to check Don't
> Know (DN) or Not Applicable (NA). I didn't have control over
> how the data was electronically collected and the vendor had
> to split the data in two since there were two seperate
> entries (ie, a written number and a check box).
> Now I am stuck with two variables: the numerical amount they
> got paid (payA) and the codes for DN/NA (payB). I need to
> merge these two together, but with a caveat. There are
> instances where a person would put a numerical answer in payA
> but would also check the NA option in payB. I need the value
> in payB to be deleted if there is a value in payA and then I
> need them to form one variable.
> Here's an example:
> payA payB
> 1 10.50 -
> 2 - 9997
> 3 6.50 9998
> What I need is one column that would have the following
> values: 1 10.50 2 9997 (could be 9997.00 if needed) 3 6.50
> Another annoying little thing is that the payA variable was
> coded as string. I know how to write the IF statement to
> delete the B value if the A value is filled in, but it won't
> work becaus A is string and B is numeric. When I try to
> convert the string to numeric, I have problems because it
> doesn't understand the decimal and just leave it out. I don't
> know the FORMATS command for currency.
> I hope all this makes since. If you can solve either of my
> problems it'd be MUCH apprecaited!!