|
Greetings once again!
I appreciate the help the group has been giving me and I wish to get some ideas on how to handle a particular data point. As the data comes from access the data element will most likely be numeric but there is the possibility that the respondent used a string code. Therefore I end up with a string variable and I am trying to think of a way to parse through the data element to test if it is a number or string. I would like to create a variable that has either the number provided by the respondent or the string response recoded as a special number representing their response. So anyone have any thoughts on how I could approach this problem? Edgar I Sanchez, Ph.D. [hidden email] http://www.apqceducation.org/ ====================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 |
|
It's really easy to test for whether a stringvar contains a number or not.
Something like this will work: compute numbervar=0. if not(sysmis(number(stringvar,f8.2))) numbervar=1. Note that you'd get a warning for every instance of stringvar not being a number so you'd better increase your max warnings with the SET command. But it's unclear to me what you want the result to be when a string is encountered. Would you give us a more concrete example. What are you expecting, how do you want to recode it, and what do you want to do with the recoded response? -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Sanchez, Edgar Sent: Thursday, May 29, 2008 3:38 PM To: [hidden email] Subject: Coding suggestions Greetings once again! I appreciate the help the group has been giving me and I wish to get some ideas on how to handle a particular data point. As the data comes from access the data element will most likely be numeric but there is the possibility that the respondent used a string code. Therefore I end up with a string variable and I am trying to think of a way to parse through the data element to test if it is a number or string. I would like to create a variable that has either the number provided by the respondent or the string response recoded as a special number representing their response. So anyone have any thoughts on how I could approach this problem? Edgar I Sanchez, Ph.D. [hidden email] http://www.apqceducation.org/ ======= 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 |
|
Here is an example of what I am anticipating as far as responses go. I
have asked respondents how many hours are specifically dedicated toward professional development in regard to utilization of some piece of software. Some respondents will simply provide the number of hours they have specifically set aside for this. For those who can not answer the question because it is too difficult we ask them to respond by typing T/D or N/A if they do not have that software in their organization. This is an example I made up on the fly but it gives you an idea of what I am anticipating. So can have responses like: "2 hrs" "2" "about 2 hrs" "T/D" or "N/A". I don't have any data right now but I am trying to prepare the code in anticipation of data analysis. One of the hardest parts for me of transitioning from SAS to SPSS is that the code for SPSS seems like disparate independent commands that are not tied to datasets and it seems like independent request without a logical flow. I know that this is largely due to the fact that I am just learning SPSS code but perhaps it may be worth learning Python. Edgar I Sanchez, PhD [hidden email] http://www.apqceducation.org/ -----Original Message----- From: ViAnn Beadle [mailto:[hidden email]] Sent: Thursday, May 29, 2008 5:54 PM To: Sanchez, Edgar; [hidden email] Subject: RE: Coding suggestions It's really easy to test for whether a stringvar contains a number or not. Something like this will work: compute numbervar=0. if not(sysmis(number(stringvar,f8.2))) numbervar=1. Note that you'd get a warning for every instance of stringvar not being a number so you'd better increase your max warnings with the SET command. But it's unclear to me what you want the result to be when a string is encountered. Would you give us a more concrete example. What are you expecting, how do you want to recode it, and what do you want to do with the recoded response? -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Sanchez, Edgar Sent: Thursday, May 29, 2008 3:38 PM To: [hidden email] Subject: Coding suggestions Greetings once again! I appreciate the help the group has been giving me and I wish to get some ideas on how to handle a particular data point. As the data comes from access the data element will most likely be numeric but there is the possibility that the respondent used a string code. Therefore I end up with a string variable and I am trying to think of a way to parse through the data element to test if it is a number or string. I would like to create a variable that has either the number provided by the respondent or the string response recoded as a special number representing their response. So anyone have any thoughts on how I could approach this problem? Edgar I Sanchez, Ph.D. [hidden email] http://www.apqceducation.org/ ======= 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 ViAnn Beadle
At 06:53 PM 5/29/2008, ViAnn Beadle wrote:
>It's really easy to test for whether a stringvar contains a number or not. > >compute numbervar=0. >if not(sysmis(number(stringvar,f8.2))) numbervar=1. > >Note that you'd get a warning for every instance of stringvar not >being a number so you'd better increase your max warnings with the SET command. Or decrease it, so you won't get all those warnings that tell you things you already know. Or, will this do it without the warnings? It's a quirk of RECODE that I only just picked up reading the documentation, and I haven't tried it: RECODE stringvar (CONVERT) (ELSE=SYSMIS) INTO numbervar. That will give the correct numeric value, not 1, when the string is a valid number. And I don't think it's supposed to give a warning. -Onward with best wishes, Richard ===================== 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 Sanchez, Edgar
For a quick and dirty approach, start by doing something like this.
Look at the variable view if a variable is string but you want to see if it the kind of variable you are worried about and it does not have legitimate negative values try something like this untested syntax. frequencies variables= odd, weird, messedup . * eyeball the output and group strings with the same meaning into sets on the recode statement. recode odd('2 hrs', '2hr' =2)('1 day' =8)('T/D', 't/d'=-1)('N/A','n/a','na')('ABC','abc'=-3)('def'=-4) (else=-5) (convert) into n_odd. value labels -1 'T/D' -2 'N/A' -3 'abc' -4 'def' -5 'other missing'. missing values n_odd (-999 thru -1). OR autorecode variables= odd, weird, messedup /into x y z. recode x (...)(convert) into n_odd. Art Kendall Social Research Consultants Sanchez, Edgar wrote: > Here is an example of what I am anticipating as far as responses go. I > have asked respondents how many hours are specifically dedicated toward > professional development in regard to utilization of some piece of > software. Some respondents will simply provide the number of hours they > have specifically set aside for this. For those who can not answer the > question because it is too difficult we ask them to respond by typing > T/D or N/A if they do not have that software in their organization. This > is an example I made up on the fly but it gives you an idea of what I am > anticipating. So can have responses like: "2 hrs" "2" "about 2 hrs" > "T/D" or "N/A". I don't have any data right now but I am trying to > prepare the code in anticipation of data analysis. > > > > One of the hardest parts for me of transitioning from SAS to SPSS is > that the code for SPSS seems like disparate independent commands that > are not tied to datasets and it seems like independent request without a > logical flow. I know that this is largely due to the fact that I am just > learning SPSS code but perhaps it may be worth learning Python. > > > > Edgar I Sanchez, PhD > > > > [hidden email] > > http://www.apqceducation.org/ > > > > > > -----Original Message----- > From: ViAnn Beadle [mailto:[hidden email]] > Sent: Thursday, May 29, 2008 5:54 PM > To: Sanchez, Edgar; [hidden email] > Subject: RE: Coding suggestions > > > > It's really easy to test for whether a stringvar contains a number or > not. > > Something like this will work: > > > > compute numbervar=0. > > if not(sysmis(number(stringvar,f8.2))) numbervar=1. > > > > Note that you'd get a warning for every instance of stringvar not being > a > > number so you'd better increase your max warnings with the SET command. > > > > But it's unclear to me what you want the result to be when a string is > > encountered. Would you give us a more concrete example. What are you > > expecting, how do you want to recode it, and what do you want to do with > the > > recoded response? > > > > -----Original Message----- > > From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of > > Sanchez, Edgar > > Sent: Thursday, May 29, 2008 3:38 PM > > To: [hidden email] > > Subject: Coding suggestions > > > > Greetings once again! > > > > > > > > > > > > I appreciate the help the group has been giving me and I > > wish to get some ideas on how to handle a particular data point. As the > > data comes from access the data element will most likely be numeric but > > there is the possibility that the respondent used a string code. > > Therefore I end up with a string variable and I am trying to think of a > > way to parse through the data element to test if it is a number or > > string. I would like to create a variable that has either the number > > provided by the respondent or the string response recoded as a special > > number representing their response. So anyone have any thoughts on how I > > could approach this problem? > > > > > > > > > > > > Edgar I Sanchez, Ph.D. > > > > > > > > [hidden email] > > > > http://www.apqceducation.org/ > > > > > > > > ======= > > 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 > > > ===================== 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
Art Kendall
Social Research Consultants |
| Free forum by Nabble | Edit this page |
