Date: Sat, 23 May 2009 20:17:00 +0000
Reply-To: Ruben van den Berg <ruben_van_den_berg@hotmail.com>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Ruben van den Berg <ruben_van_den_berg@hotmail.com>
Subject: Problem converting string to numeric
Content-Type: multipart/alternative;
Dear all,
I'm trying to create a table that provides information on a number of variables. Specifically, I want to compare dictionary information with frequency information (are all values present in the data labelled? are there any labelled values not present in the data? how many different values are present in the data/dictionary?) etcetera. I create a small test data set in order to keep things under control.
However, SPSS refuses to convert a string (the values from the frequency table) into numeric (in order to be used as a key variable for matching the datasets). My suspicion is that it may have something to do with the decimal separator being a comma instead of a period but after replacing it, I get the same error messages. Could anyone please have a look at my syntax? Since it's rather long, I've indicated where things turn bad with *@1 and *@2.
Fortunately, I've a plan B for now (convert the numeric in the other dataset to string) but I am curious why plan A doesn't work.
Thanks a lot in advance and thanks once again to those who provided me with such wonderful assistance over the last couple of weeks!!
Ruben van den Berg
Amsterdam, the Netherlands
***Begin of syntax:.
DATAS CLO ALL.
CD 'C:\Tests'.
SET TNU VAL.
SET SEED=123456.
NEW FIL.
INP PRO.
LOOP #I=1 to 60.
COMP ID=#I.
END CAS.
END LOOP.
END FIL.
END INP PRO.
EXE.
DATAS NAM Testdata.
COMP sex=RND(RV.UNI(1,2)).
COMP age=RND(RV.UNI(1,5)).
COMP status=RND(RV.UNI(0,3)).
EXE.
VAL LAB sex 1 Male
2 Female
/age 1 18-36 years
2 37-54 years
3 55-72 years
4 73 years and over
99 Unknown
/status 1 married
2 bachelor
3 divorced or widowed.
DATASET DECLARE Freq.
OMS
/SELECT TABLES
/IF COMMANDS = ["Frequencies"]
SUBTYPES = ["Frequencies"]
/DESTINATION FORMAT = SAV NUMBERED = TableNumber_
OUTFILE = Freq
VIEWER = NO
/TAG = "Freq".
OMS
/SELECT TABLES
/IF COMMANDS = ["File Information"]
SUBTYPES = ["Variable Labels"]
/DESTINATION VIEWER = NO
/TAG = "Varlab".
DATASET DECLARE Vallab.
OMS
/SELECT TABLES
/IF COMMANDS = ["File Information"]
SUBTYPES = ["Variable Values"]
/DESTINATION FORMAT = SAV NUMBERED = TableNumber_
OUTFILE = Vallab
VIEWER = NO
/TAG = "Vallab".
DISP DIC.
FRE sex age status.
OMSEND.
DATAS ACT Vallab.
REN VAR (Var1 Var2=Variable Value).
DATAS ACT Freq.
SEL IF Var2 NE "Total".
EXE.
*@1 Attempt 1:.
COMP Value=NUM(Var2,N4).
EXE.
*@1 "Invalid numeric field" due to comma separator??.
*@2 Attempt 2:.
STR Var2B(A5).
COMP Var2B=REPLACE(Var2,",",".").
EXE.
COMP Value=NUM(Var2B,N4).
EXE.
*@2 Doesn't work either :-(.
MATC FIL FIL Freq
/FIL Vallab
/BY Variable Value.
DATAS NAM Combi.
DATAS CLO Freq.
DATAS CLO Vallab.
_________________________________________________________________
What can you do with the new Windows Live? Find out
http://www.microsoft.com/windows/windowslive/default.aspx
[text/html]