Hi there,
I am trying to count the number of '~' in my string variable which looks like: oos_service_dates_CONCAT 2020-10-20~2020-10-29~2020-11-05~2020-11-12~2020-12-03 2020-10-20~2020-10-27 2020-10-21 Essentially the plan is to count the dates by counting the number of deliniators (~) and then add one. I have tried this, which runs, but every case is '0' COUNT OoS_Count=oos_service_dates_CONCAT('~'). Any ideas?? Thanks in advance -- 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 |
Hi there, COUNT counts across variables - not within. Try this:
COMPUTE freq = 0. LOOP #i=1 to 1000 /* max number of letters */. COMPUTE freq = freq + CHAR.INDEX(CHAR.SUBSTR(oos_service_dates_CONCAT,#i,1),'~'). END LOOP. EXECUTE. GL, Mario - Mario Giesel Munich Germany Am Freitag, 19. Februar 2021, 04:41:03 MEZ hat Erin44 <[hidden email]> Folgendes geschrieben: Hi there, I am trying to count the number of '~' in my string variable which looks like: oos_service_dates_CONCAT 2020-10-20~2020-10-29~2020-11-05~2020-11-12~2020-12-03 2020-10-20~2020-10-27 2020-10-21 Essentially the plan is to count the dates by counting the number of deliniators (~) and then add one. I have tried this, which runs, but every case is '0' COUNT OoS_Count=oos_service_dates_CONCAT('~'). Any ideas?? Thanks in advance -- 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 |
In reply to this post by Erin44
You have to step thru the string character by character to test the current character against the tilde character using the Loop-end loop and char.substr(string.name,j,1) where j is the index variable in loop-end loop command.
Like this Compute ntilde=0. Loop j=1 to 25. Where 25 is length of oos_service_dates_CONCAT. + if (char.substr(oos_service_dates_CONCAT,j,1) eq '~') ntilde=ntilde+1. End loop. Gene Maguin -----Original Message----- From: SPSSX(r) Discussion <[hidden email]> On Behalf Of Erin44 Sent: Wednesday, February 17, 2021 4:41 PM To: [hidden email] Subject: count the number of '~' in string Hi there, I am trying to count the number of '~' in my string variable which looks like: oos_service_dates_CONCAT 2020-10-20~2020-10-29~2020-11-05~2020-11-12~2020-12-03 2020-10-20~2020-10-27 2020-10-21 Essentially the plan is to count the dates by counting the number of deliniators (~) and then add one. I have tried this, which runs, but every case is '0' COUNT OoS_Count=oos_service_dates_CONCAT('~'). Any ideas?? Thanks in advance -- 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 |
In reply to this post by Erin44
Bouncing off Mario:
"COMPUTE freq = 0. LOOP #i=1 to 1000 /* max number of letters */. COMPUTE freq = freq + CHAR.INDEX(CHAR.SUBSTR(oos_service_dates_CONCAT,#i,1),'~'). END LOOP. EXECUTE." Lose the initialization and the EXECUTE. LOOP #=1 to CHAR.LENGTH(oos_service_dates_CONCAT). COMPUTE freq=SUM(freq,CHAR.INDEX(CHAR.SUBSTR(oos_service_dates_CONCAT,#,1),'~'). END LOOP." Rather ponderous variable name there. ===================== 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
|
Good reminder that SUM() returns a valid result when there is at least one
valid argument. David Marso-2 wrote > LOOP #=1 to CHAR.LENGTH(oos_service_dates_CONCAT). > COMPUTE > freq=SUM(freq,CHAR.INDEX(CHAR.SUBSTR(oos_service_dates_CONCAT,#,1),'~'). > END LOOP." > > Rather ponderous variable name there. ----- -- Bruce Weaver [hidden email] http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." NOTE: My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. -- 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
--
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/). |
Or this one liner. spssinc trans result=freq /formula "sum(item =='~' for item in oos_service_dates_CONCAT)". On Sat, Feb 20, 2021 at 4:11 PM Bruce Weaver <[hidden email]> wrote: Good reminder that SUM() returns a valid result when there is at least one |
Thanks so much!
That syntax worked perfectly. -- 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 |
In reply to this post by Bruce Weaver
thank you :)
-- 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 |
Free forum by Nabble | Edit this page |