Commas to separate numbers

Other discussions about CSPro
MrTaco
Posts: 127
Joined: November 18th, 2014, 1:55 am

Commas to separate numbers

Postby MrTaco » March 26th, 2017, 2:16 pm

Dear all

I need a logic to automatically insert commas after every number

eg. If there are more than one person for a condition, put commas to separate person numbers. i.e. 1, 3, 6.

but i also want to restrict to only insert numbers and commas on string

thanks

Gregory Martin
Posts: 852
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Commas to separate numbers

Postby Gregory Martin » March 27th, 2017, 8:53 am

I'm not sure exactly what you are trying to do, but this code would create a list of row numbers of all men in the household:

string maleRowNumbers;

do numeric rowNum = 1 while rowNum <= count(SEX)

    if SEX(rowNum) = 1 then // add the row number

        if length(maleRowNumbers) > 0 then
            maleRowNumbers = maleRowNumbers + ", ";
        endif;

        maleRowNumbers = maleRowNumbers + maketext("%d",rowNum);

    endif;

enddo;


Perhaps you can adopt that for your purposes.

MrTaco
Posts: 127
Joined: November 18th, 2014, 1:55 am

Re: Commas to separate numbers

Postby MrTaco » March 27th, 2017, 9:09 am

it will be Question a Person health condition eg. person 1 and person 2 has TB I should be able to separate 1,3 when i enter
eesss.png
eesss.png (2.13 KiB) Viewed 584 times


meaning person 1(1) then person 2 (3) but it's all in one question but i didn't want to do it as String

Gregory Martin
Posts: 852
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Commas to separate numbers

Postby Gregory Martin » March 27th, 2017, 10:46 am

The only way you'll be able to collect this is using a string. A numeric field won't allow you to capture multiple sets of information like this.

MrTaco
Posts: 127
Joined: November 18th, 2014, 1:55 am

Re: Commas to separate numbers

Postby MrTaco » March 27th, 2017, 2:03 pm

then is there a way to restrict it to only allow numbers and commas

Gregory Martin
Posts: 852
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Commas to separate numbers

Postby Gregory Martin » March 27th, 2017, 6:24 pm

There is no direct way to do this. You could write logic to test this though, something like:

PROC FIELD

    do numeric ctr = 1 while ctr <= length(FIELD)

        if poschar("0123456789, ",FIELD[ctr:1]) = 0 then
            errmsg("You can only enter digits and commas");
            reenter;
        endif;

    enddo;


Return to “Other”