Hi!
I'd like to check through any dataset for a set of variables, and if any of them does not exist, I want to compute it as $SYSMIS, otherwise leave as is. Any ideas how this could be done? Many Thanks /ogge |
Administrator
|
That will require either python or basic scripting
--
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?" |
Well if you do not have to 'check' - just make sure that all the variables are there I do it on every job I work on .. I create a dummy datafile with all variables that should be present Add the data provided and sel out only those new cases INSERT FILE= "StructureFile.sps" SYNTAX=BATCH ERROR=STOP CD=NO. EXECUTE. GET FILE "DataStructure.sav". ADD FILES FILE = * / IN= struct / FILE = "provided file Raw.sav" / IN= rawdat / MAP. SEL IF (rawdat=1). EXECUTE. Thanks! ********************************* Notice: This e-mail and any attachments may contain confidential and privileged information. If you are not the intended recipient, please notify the sender immediately by return e-mail, do not use the information, delete this e-mail and destroy any copies. Any dissemination or use of this information by a person other than the intended recipient is unauthorized and may be illegal. Email transmissions cannot be guaranteed to be secure or error free. The sender therefore does not accept any liability for errors or omissions in the contents of this message that arise as a result of email transmissions. -----Original Message----- That will require either python or basic scripting -- oggesjolin wrote > Hi! > > I'd like to check through any dataset for a set of variables, and if > any of them does not exist, I want to compute it as $SYSMIS, otherwise > leave as is. > > Any ideas how this could be done? > > Many Thanks > /ogge ----- 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?" -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Compute-variable-if-it-doesn-t-exist-tp5729047p5729048.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 |
In reply to this post by oggesjolin
This will do it, assuming all the required
variables are numeric. Just list the variables in required.
If the list is long, this can be modified. begin program. import spss, spssaux # list of required variables # case must match required="abc def ghi Name" required = required.split() create = spssaux.VariableDict().variables todo = set(required) - set(create) cmds = ["compute %s = $sysmis." % item for item in todo] if cmds: spss.Submit(cmds) end program. Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] phone: 720-342-5621 From: oggesjolin <[hidden email]> To: [hidden email] Date: 03/25/2015 05:50 AM Subject: [SPSSX-L] Compute variable if it doesn't exist Sent by: "SPSSX(r) Discussion" <[hidden email]> Hi! I'd like to check through any dataset for a set of variables, and if any of them does not exist, I want to compute it as $SYSMIS, otherwise leave as is. Any ideas how this could be done? Many Thanks /ogge -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Compute-variable-if-it-doesn-t-exist-tp5729047.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 |
Many thanks Jon, exactly what I wanted!
|
In reply to this post by Jon K Peck
If you dataset should look just like a reference dataset (same variables), you could also use APPLY DICTIONARY with the /NEWVARS subcommand. "
"NEWVARS is required to create new variables in the active (target) dataset.": http://www-01.ibm.com/support/knowledgecenter/SSLVMB_22.0.0/com.ibm.spss.statistics.reference/spss/base/syn_apply_dictionary_newvars.htm 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: Jon K Peck <[hidden email]> >To: [hidden email] >Sent: Wednesday, March 25, 2015 2:20 PM >Subject: Re: [SPSSX-L] Compute variable if it doesn't exist > > > >This will do it, assuming all the required variables are numeric. Just list the variables in required. >If the list is long, this can be modified. > >begin program. >import spss, spssaux > ># list of required variables ># case must match >required="abc def ghi Name" > >required = required.split() >create = spssaux.VariableDict().variables >todo = set(required) - set(create) >cmds = ["compute %s = $sysmis." >if cmds: > spss.Submit(cmds) >end program. > > > >Jon Peck (no "h") aka Kim >Senior Software Engineer, IBM >[hidden email] >phone: 720-342-5621 > > > > >From: >To: [hidden email] >Date: 03/25/2015 05:50 AM >Subject: [SPSSX-L] Compute variable if it doesn't exist >Sent by: "SPSSX(r) Discussion" <[hidden email]> >>________________________________ > > > >Hi! > >I'd like to check through any dataset for a set of variables, and if any of >them does not exist, I want to compute it as $SYSMIS, otherwise leave as is. > >Any ideas how this could be done? > >Many Thanks >/ogge > > > > > >-- >View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Compute-variable-if-it-doesn-t-exist-tp5729047.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 > > > > > > > >===================== 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 |
Even better yet! Neat and tidy.
|
Administrator
|
In reply to this post by Albert-Jan Roskam-2
Very nice, Albert-Jan! Once again, it pays to RTFM! ;-)
--
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
|
Indeed! I retract my script/python assertion. --
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 oggesjolin
It is often shooting yourself in the foot to use symis when you know why the variable value is missing. It is missing because "the source did not use that variable". Try assigning a labelled user-missing value.
Art Kendall
Social Research Consultants |
Well.. No. That would be fine if the end data was only to be used in SPSS,
but I sure don't want a bunch of strange missing values in my database, I want NULL. -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Compute-variable-if-it-doesn-t-exist-tp5729047p5729101.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 |
In reply to this post by Art Kendall
No, in this case I'm writing the data to a .csv to import into db, I want NULL where there really is no data.
|
Free forum by Nabble | Edit this page |