|
Dear list: I have a large data set with a variable called IDNUM which has 8 digits. I want to select those cases that start with 101, 102, 103, 104, 105, 107, 114, 117, or 118. I don't care what numbers come after the first three. I check Raynald Levesque's site and could not find a syntax program for selecting cases based on the first three values of a numerical variable. Suggestions appreciated. thanks,
Martin F. Sherman, Ph.D. Professor of Psychology Director of Masters Education: Thesis Track Loyola College Psychology Department 222 B Beatty Hall 4501 North Charles Street Baltimore, MD 21210 410 617-2417 (office) 410 617-5341 (fax) [hidden email] ===================== 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 |
|
Martin, a little more detail for the list might help.
IDNUM is a numeric not a string? What is the format - F8.0, N8? Are all the IDNUM actually 8 digits long? Would 10101 be a possible IDNUM or would it have to be 10101000 or 00010101? Would 10101.01 or 10101.1 be valid? Catherine At 1/10/2008 04:47 PM, Martin Sherman wrote: >Dear list: I have a large data set with a variable called IDNUM which has >8 digits. I want to select those cases that start with 101, 102, 103, >104, 105, 107, 114, 117, or 118. I don't care what numbers come after the >first three. I check Raynald Levesque's site and could not find a syntax >program for selecting cases based on the first three values of a numerical >variable. Suggestions appreciated. thanks, > > > >Martin F. Sherman, Ph.D. >Professor of Psychology >Director of Masters Education: Thesis Track >Loyola College >Psychology Department >222 B Beatty Hall >4501 North Charles Street >Baltimore, MD 21210 > >410 617-2417 (office) >410 617-5341 (fax) > >[hidden email] > >===================== >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 msherman
Hi Dr. Sherman,
I think one way to approach this is to treat the source as a string variable, and then convert the extracted values back to numbers within the ANY() function. The following example takes this approach, and therefore allows me to use several string functions, evaluate for the selection criteria, and then create a binary flag variable on which I can filter or execute a SELECT IF command. COMPUTE flag = ANY((NUMBER(SUBSTR(LTRIM(RTRIM(STRING(id,F8))),1,3),F8)), 101,102,103,104,105,107,114,117,118). I hope this helps. If I can offer any further assistance or clarification, please do not hesitate to ask. Good Luck, John Norton SPSS Inc. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Martin Sherman Sent: Thursday, January 10, 2008 3:47 PM To: [hidden email] Subject: select cases from part of idnum variable Dear list: I have a large data set with a variable called IDNUM which has 8 digits. I want to select those cases that start with 101, 102, 103, 104, 105, 107, 114, 117, or 118. I don't care what numbers come after the first three. I check Raynald Levesque's site and could not find a syntax program for selecting cases based on the first three values of a numerical variable. Suggestions appreciated. thanks, Martin F. Sherman, Ph.D. Professor of Psychology Director of Masters Education: Thesis Track Loyola College Psychology Department 222 B Beatty Hall 4501 North Charles Street Baltimore, MD 21210 410 617-2417 (office) 410 617-5341 (fax) [hidden email] ===================== 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 msherman
compute newidnum= trunc (idnum/10000).
recode newidnum(101 thru 105, 107, 114, 117,118=1)(else=0) into mygroup. select if mygroup eq 1). OR filter by mygroup. Art Kendall Social Research Consultants Martin Sherman wrote: > Dear list: I have a large data set with a variable called IDNUM which has 8 digits. I want to select those cases that start with 101, 102, 103, 104, 105, 107, 114, 117, or 118. I don't care what numbers come after the first three. I check Raynald Levesque's site and could not find a syntax program for selecting cases based on the first three values of a numerical variable. Suggestions appreciated. thanks, > > > > Martin F. Sherman, Ph.D. > Professor of Psychology > Director of Masters Education: Thesis Track > Loyola College > Psychology Department > 222 B Beatty Hall > 4501 North Charles Street > Baltimore, MD 21210 > > 410 617-2417 (office) > 410 617-5341 (fax) > > [hidden email] > > ===================== > 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 Catherine Kubitschek
Martin, thanks for the information.
You've gotten a couple of good answers already. Art Kendall's solution works because your data is a standard format & width. At 1/11/2008 08:49 AM, Art Kendall wrote: >compute newidnum= trunc (idnum/10000). >recode newidnum(101 thru 105, 107, 114, 117,118=1)(else=0) into mygroup. > >select if mygroup eq 1). > OR >filter by mygroup. John Norton's solution would work regardless of exactly what your data looked like: At 1/10/2008 05:49 PM, Norton, John wrote: >Hi Dr. Sherman, > >I think one way to approach this is to treat the source as a string >variable, and then convert the extracted values back to numbers within the >ANY() function. The following example takes this approach, and therefore >allows me to use several string functions, evaluate for the selection >criteria, and then create a binary flag variable on which I can filter or >execute a SELECT IF command. > >COMPUTE flag = > ANY((NUMBER(SUBSTR(LTRIM(RTRIM(STRING(id,F8))),1,3),F8)), > 101,102,103,104,105,107,114,117,118). At 1/10/2008 08:44 PM, Martin Sherman wrote: >Catherine: The format is F7.0. The lowest values are below and >1010002 >1010007 >1010009 >1010016 > ..... >..... >1181319 Here is the highest value. My concern is only with the first >three digits. > >thanks, > ><snip> > >At 1/10/2008 04:47 PM, Martin Sherman wrote: > >Dear list: I have a large data set with a variable called IDNUM which has > >8 digits. I want to select those cases that start with 101, 102, 103, > >104, 105, 107, 114, 117, or 118. I don't care what numbers come after the > >first three. I check Raynald Levesque's site and could not find a syntax > >program for selecting cases based on the first three values of a numerical > >variable. Suggestions appreciated. thanks, ===================== 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 |
| Free forum by Nabble | Edit this page |
