|
Administrator
|
You could do something like this, assuming your Last Name variable is called LastName:
COMPUTE LastNameFlag = LTRIM(RTRIM(LastName)) NE "". FORMATS LastNameFlag (f1). VARIABLE LABELS LastNameFlag "Last name present". VALUE LABELS LastNameFlag 1 "1-Yes" 0 "0-No". You may not actually need the LTRIM and RTRIM -- I don't have SPSS on this machine to test it.
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
Administrator
|
Of course we can leave out the LTRIM(RTRIM(##)).
-- DATA LIST LIST / x (A10). BEGIN DATA jones weaver end data. COMPUTE Flag=x NE " ". LIST. x Flag jones 1.0000 weaver 1.0000 .0000 Number of cases read: 3 Number of cases listed: 3
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?" |
In reply to this post by Bruce Weaver
Thanks for your help! I tried your syntax as below:
COMPUTE PREP_NAMEFlag = PREPAPER_NAME_2011 NE " ". FORMATS PREP_NAMEFlag (f10). but keep getting the following message: IBS SPSS statistic processor is ready. Transformation pending When I checked the data, a new variable of PREP_NAME is created with a period in all records. I waited for one hour and terminated it. Not sure what is wrong. Any suggestion? |
Joanna,
Insert an 'Execute' after the 'Compute' statement. COMPUTE PREP_NAMEFlag = PREPAPER_NAME_2011 NE " ". EXECUTE . FORMATS PREP_NAMEFlag (f10). Transformation pending generally indicates that the system is waiting for 'Execute' to complete the process. Brian -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Joanna Koh Sent: Friday, April 12, 2013 4:13 PM To: [hidden email] Subject: Re: change a string variable containing last names into 0 and 1 Thanks for your help! I tried your syntax as below: COMPUTE PREP_NAMEFlag = PREPAPER_NAME_2011 NE " ". FORMATS PREP_NAMEFlag (f10). but keep getting the following message: IBS SPSS statistic processor is ready. Transformation pending When I checked the data, a new variable of PREP_NAME is created with a period in all records. I waited for one hour and terminated it. Not sure what is wrong. Any suggestion? -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/change-a-string-variable-containing-last-names-into-0-and-1-tp5719418p5719431.html Sent from the SPSSX Discussion mailing list archive at 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 |
In reply to this post by Joanna Koh
Nothing is wrong. Just use an EXECUTE or any other command that forces a data pass (e.g. FREQUENCIES).
Regards, Albert-Jan ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >________________________________ > From: Joanna Koh <[hidden email]> >To: [hidden email] >Sent: Friday, April 12, 2013 10:12 PM >Subject: Re: [SPSSX-L] change a string variable containing last names into 0 and 1 > > >Thanks for your help! I tried your syntax as below: > >COMPUTE PREP_NAMEFlag = PREPAPER_NAME_2011 NE " ". >FORMATS PREP_NAMEFlag (f10). > >but keep getting the following message: > >IBS SPSS statistic processor is ready. Transformation pending > >When I checked the data, a new variable of PREP_NAME is created with a >period in all records. > >I waited for one hour and terminated it. Not sure what is wrong. Any >suggestion? > > > >-- >View this message in context: http://spssx-discussion.1045642.n5.nabble.com/change-a-string-variable-containing-last-names-into-0-and-1-tp5719418p5719431.html >Sent from the SPSSX Discussion mailing list archive at 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 |
Administrator
|
In reply to this post by bdates
And since PREP_NAMEFlag will only have values of 1 or 0, I would make that format F1, not F10. ;-)
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
In reply to this post by Albert-Jan Roskam
quite right, but note that you should use EXECUTE sparingly as it involves a full pass of the data. Generally, if you have several transformation statements, e.g. several COMPUTEs, then just use one EXECUTE at the end and even that isn't necessary if your next statement is a SAVE, SORT, etc. This is explained in better detail in the Syntax Command Reference manual which is available via Help.
regards, Robert |
Thanks everyone! It works after I added execute or frequencies. I also tried the following and it works very well, too.
DO IF ((PREPARER_NAME=" ")). COMPUTE DUMMY_prep = 0. ELSE. COMPUTE DUMMY_prep = 1. END IF. EXECUTE. Do you have any opinion about which syntax (between do if and flag) is better in terms of speed or efficiency? |
Free forum by Nabble | Edit this page |