I’d rather know the answer rather than testing to get the answer.
Given define !twochars () !quote(!substr(!eval(!JOB_DATAFILEROOT), 2, 2)) !enddefine. !twochars will return a two character string of a numeric value, e.g., 18. Will this next line work? compute rid=number(!twochars,f2.0). Thanks, Gene Maguin |
That should be fine. On Mon, Feb 26, 2018 at 9:47 AM, Maguin, Eugene <[hidden email]> wrote:
|
Jon,
I had been using this little piece of code that you had given me to insert the participant id into the data file and it worked file. However,
when I tried to do the same thing today but to insert the id as numeric using what I had previously posted, it did not work. I went back and looked at one of the spv files and saw what’s copied here. 2676 0 M> * extract and add participant id. 2677 0 M> define 2678 0 M> !twochars () 2679 0 M> !quote(!substr(!eval(!JOB_DATAFILEROOT), 2, 2)) 2680 0 M> !enddefine. 2681 0 M> string rid(a2). 2682 0 M> compute rid='17' 2683 0 M> . I need some help understanding what’s happening. So, first, I don’t understand how if rid is A2, and is set equal to ‘17’, how the value the
data file is 17 a2 format. It seems as if there is some sleight of hand to strip off the apostrophes. There’s not any sleight of hand but what is happening? What I had in mind
compute rid=number(!twochars,f2.0). didn’t work and rid was sysmis. So, is the solution compute rid=number(char.substr(!twochars,2,2),f2.0). Gene Maguin From: Jon Peck [mailto:[hidden email]]
That should be fine. On Mon, Feb 26, 2018 at 9:47 AM, Maguin, Eugene <[hidden email]> wrote:
-- Jon K Peck |
In the COMPUTE statement, you are assigning a string literal, which is indicated by the quotes around 17. The transformation parser knows that it is a string because it is quoted and that the value is the string 17. The quotes just tell the parser that this is a string literal rather than a numeric literal. On the second point, the value of rid is sysmis because the value of !twochars can't be converted to a number using f2.0 format. You could declare rid to be a string, say, STRING rid(a10), allowing for anything extra that might be there and then see what you are actually trying to convert by just doing COMPUTE rid = !twochars. On Mon, Feb 26, 2018 at 12:49 PM, Maguin, Eugene <[hidden email]> wrote:
|
Thanks.
Ok. so I really do have use two steps to get !twochars to a numeric value. So it seems like this ought to work but it doesn’t. As I understand the contents of
!job_...., it is the file name which here is 17_03month … for the first file. Thus, !twochars is ‘17’. #s is declared a2 and compute #s=!twochars should give #s a value of 17 in A format.
However, (I’m now looking at the macro documentation) and I see that !substr works like char.substr. So: Given that the file name begins 17_03month, shouldn’t
the ‘from’ value be 1 and not 2? However, I agree that a ‘from’ value of 2 did work correctly in the other PDF iteration. define !twochars ()
!quote(!substr(!eval(!JOB_DATAFILEROOT), 2, 2))
!enddefine.
String #s(a2). Compute #s=!twochars. Compute rid=number(#s,f2.0). From: Jon Peck [mailto:[hidden email]]
In the COMPUTE statement, you are assigning a string literal, which is indicated by the quotes around 17. The transformation parser knows that it is a string because it is quoted and that the value is the
string 17. The quotes just tell the parser that this is a string literal rather than a numeric literal. On the second point, the value of rid is sysmis because the value of !twochars can't be converted to a number using f2.0 format. You could declare rid to be a string, say, STRING rid(a10), allowing for anything
extra that might be there and then see what you are actually trying to convert by just doing COMPUTE rid = !twochars. On Mon, Feb 26, 2018 at 12:49 PM, Maguin, Eugene <[hidden email]> wrote:
-- Jon K Peck |
Administrator
|
In reply to this post by Maguin, Eugene
What is !JOB_DATAFILEROOT?
Presumably is is embedded in a DEFINE !ENDDEFINE block somewhere. I changed your first 2 to a 1 so it would return 21 rather than 1x ;-) DEFINE !JOB_DATAFILEROOT () 21xyz !ENDDEFINE. define !twochars () !quote(!substr(!eval(!JOB_DATAFILEROOT), 1, 2)) !enddefine. /* !twochars will return a two character string of a numeric value, e.g., 18. Will this next line work? NEW FILE. DATASET CLOSE ALL. DATA LIST FREE / x. BEGIN DATA 1 END DATA. SET PRINTBACK ON MPRINT ON. ECHO !twochars. compute rid=number(!twochars,f2.0). LIST. ECHO !twochars. 4381 0 M> ECHO '21' 4382 0 M> . 4383 0 M> compute rid=number('21' ,f2.0). 21 x rid 1.00 21.00 Maguin, Eugene wrote > Jon, > I had been using this little piece of code that you had given me to insert > the participant id into the data file and it worked file. However, when I > tried to do the same thing today but to insert the id as numeric using > what I had previously posted, it did not work. I went back and looked at > one of the spv files and saw what’s copied here. > > 2676 0 M> * extract and add participant id. > 2677 0 M> define > 2678 0 M> !twochars () > 2679 0 M> !quote(!substr(!eval(!JOB_DATAFILEROOT), 2, 2)) > 2680 0 M> !enddefine. > 2681 0 M> string rid(a2). > 2682 0 M> compute rid='17' > 2683 0 M> . > > I need some help understanding what’s happening. So, first, I don’t > understand how if rid is A2, and is set equal to ‘17’, how the value the > data file is 17 a2 format. It seems as if there is some sleight of hand to > strip off the apostrophes. There’s not any sleight of hand but what is > happening? > > What I had in mind > compute rid=number(!twochars,f2.0). > didn’t work and rid was sysmis. So, is the solution > > compute rid=number(char.substr(!twochars,2,2),f2.0). > > > Gene Maguin > > > > From: Jon Peck [mailto: > jkpeck@ > ] > Sent: Monday, February 26, 2018 1:12 PM > To: Maguin, Eugene < > emaguin@ > > > Cc: SPSS List < > SPSSX-L@.uga > > > Subject: Re: [SPSSX-L] macro ref in a function call > > That should be fine. > > On Mon, Feb 26, 2018 at 9:47 AM, Maguin, Eugene < > emaguin@ > <mailto: > emaguin@ > >> wrote: > I’d rather know the answer rather than testing to get the answer. > Given > > define !twochars () > !quote(!substr(!eval(!JOB_DATAFILEROOT), 2, 2)) > !enddefine. > > !twochars will return a two character string of a numeric value, e.g., 18. > Will this next line work? > > compute rid=number(!twochars,f2.0). > > Thanks, Gene Maguin > ===================== To manage your subscription to SPSSX-L, send a > message to > LISTSERV@.UGA > <mailto: > LISTSERV@.UGA > > (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 > > > > -- > Jon K Peck > jkpeck@ > <mailto: > jkpeck@ > > > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@.UGA > (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 ----- 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?" -- Sent from: http://spssx-discussion.1045642.n5.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
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 Maguin, Eugene
The macro definition for !JOB_DATAFILEROOT and the other macros, as it says in the command help, is quoted, e.g., "17_03", so you can either !unquote it and start with the first character or just start with the second one, i.e., skip over the quote, which is why the !twochars macro started with position 2. On Mon, Feb 26, 2018 at 2:11 PM, Maguin, Eugene <[hidden email]> wrote:
|
In reply to this post by David Marso
!JOB_DATAFILEROOT is part of the Process Data Files command accessible from the utilities menu.
-----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Marso Sent: Monday, February 26, 2018 4:14 PM To: [hidden email] Subject: Re: macro ref in a function call What is !JOB_DATAFILEROOT? Presumably is is embedded in a DEFINE !ENDDEFINE block somewhere. I changed your first 2 to a 1 so it would return 21 rather than 1x ;-) DEFINE !JOB_DATAFILEROOT () 21xyz !ENDDEFINE. define !twochars () !quote(!substr(!eval(!JOB_DATAFILEROOT), 1, 2)) !enddefine. /* !twochars will return a two character string of a numeric value, e.g., 18. Will this next line work? NEW FILE. DATASET CLOSE ALL. DATA LIST FREE / x. BEGIN DATA 1 END DATA. SET PRINTBACK ON MPRINT ON. ECHO !twochars. compute rid=number(!twochars,f2.0). LIST. ECHO !twochars. 4381 0 M> ECHO '21' 4382 0 M> . 4383 0 M> compute rid=number('21' ,f2.0). 21 x rid 1.00 21.00 Maguin, Eugene wrote > Jon, > I had been using this little piece of code that you had given me to > insert the participant id into the data file and it worked file. > However, when I tried to do the same thing today but to insert the id > as numeric using what I had previously posted, it did not work. I went > back and looked at one of the spv files and saw what’s copied here. > > 2676 0 M> * extract and add participant id. > 2677 0 M> define > 2678 0 M> !twochars () > 2679 0 M> !quote(!substr(!eval(!JOB_DATAFILEROOT), 2, 2)) > 2680 0 M> !enddefine. > 2681 0 M> string rid(a2). > 2682 0 M> compute rid='17' > 2683 0 M> . > > I need some help understanding what’s happening. So, first, I don’t > understand how if rid is A2, and is set equal to ‘17’, how the value > the data file is 17 a2 format. It seems as if there is some sleight of > hand to strip off the apostrophes. There’s not any sleight of hand but > what is happening? > > What I had in mind > compute rid=number(!twochars,f2.0). > didn’t work and rid was sysmis. So, is the solution > > compute rid=number(char.substr(!twochars,2,2),f2.0). > > > Gene Maguin > > > > From: Jon Peck [mailto: > jkpeck@ > ] > Sent: Monday, February 26, 2018 1:12 PM > To: Maguin, Eugene < > emaguin@ > > > Cc: SPSS List < > SPSSX-L@.uga > > > Subject: Re: [SPSSX-L] macro ref in a function call > > That should be fine. > > On Mon, Feb 26, 2018 at 9:47 AM, Maguin, Eugene < > emaguin@ > <mailto: > emaguin@ > >> wrote: > I’d rather know the answer rather than testing to get the answer. > Given > > define !twochars () > !quote(!substr(!eval(!JOB_DATAFILEROOT), 2, 2)) !enddefine. > > !twochars will return a two character string of a numeric value, e.g., 18. > Will this next line work? > > compute rid=number(!twochars,f2.0). > > Thanks, Gene Maguin > ===================== To manage your subscription to SPSSX-L, send a > message to > LISTSERV@.UGA > <mailto: > LISTSERV@.UGA > > (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 > > > > -- > Jon K Peck > jkpeck@ > <mailto: > jkpeck@ > > > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@.UGA > (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 ----- 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?" -- Sent from: http://spssx-discussion.1045642.n5.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
|
But my question is what does it evaluate to? Are you sure the correct substring is the 2nd and 3rd characters? On Mon, Feb 26, 2018 at 4:45 PM, Maguin, Eugene <[hidden email]> wrote: !JOB_DATAFILEROOT is part of the Process Data Files command accessible from the utilities menu.
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?" |
Free forum by Nabble | Edit this page |