Dear All
Hope you are good. I am new here.
The problem I have been through is I want to write a function that will check all the option's values of the multiple select question from the valuesets and put them in an array. After doing so, that function will check the options entered by the interviewer.
The function will be able to place the selected options in their actual positions.
Right now, I am using the following logic to handle the problem:
PROC GLOBAL
array alpha (2) responses_2_1_3(6) = "01", "02", "03", "04","96","98";
PROC Q2_1_3
numeric ctr;
do ctr = 6 while ctr >= 1 by -1
if pos(responses_2_1_3(ctr),$) then
$[(ctr * 2 - 1):2] = responses_2_1_3(ctr);
else
$[(ctr * 2 - 1):2] = "";
endif;
enddo;
This logic has a problem that if INTERVIEWER selects the last option first and the 1st value at the end then this logic fails. Please help
Multi select Options at their actual positions
Re: Multi select Options at their actual positions
The problem is that you are modifying the field at the same time you are reading the values from it. Try setting the values into a temporary variable and then copying from the temporary into the field after all the values have been read.
numeric ctr;
string temp;
do ctr = 1 while ctr <= length(responses_2_1_3)
if pos(responses_2_1_3(ctr),$) then
temp[(ctr * 2 - 1):2] = responses_2_1_3(ctr);
else
temp[(ctr * 2 - 1):2] = "";
endif;
enddo;
string temp;
do ctr = 1 while ctr <= length(responses_2_1_3)
if pos(responses_2_1_3(ctr),$) then
temp[(ctr * 2 - 1):2] = responses_2_1_3(ctr);
else
temp[(ctr * 2 - 1):2] = "";
endif;
enddo;
Re: Multi select Options at their actual positions
Oh thank you so much for the help. I don't know why shouldn't I think like that..
Another thing is: can't we write a general function in PROC GLOBAL that we just call in the PROC and will work for every multiple select question having different length and different options?
Like: Q2 have 3 options ("01", "02", "03")and Q4 have 6 options ("01","02","03","04","05","96")
Another thing is: can't we write a general function in PROC GLOBAL that we just call in the PROC and will work for every multiple select question having different length and different options?
Like: Q2 have 3 options ("01", "02", "03")and Q4 have 6 options ("01","02","03","04","05","96")
Re: Multi select Options at their actual positions
Yes you can write functions in proc global and use them in procs. http://www.csprousers.org/help/CSPro/us ... tions.html
Your function would be something like:
Your function would be something like:
PROC GLOBAL
function string adjustCheckboxPositions(string fieldValue, array alpha(2) responses)
string temp;
do numeric ctr = 1 while ctr <= length(responses)
if pos(responses(ctr),fieldValue) then
temp[(ctr * 2 - 1):2] = responses(ctr);
else
temp[(ctr * 2 - 1):2] = "";
endif;
enddo;
adjustCheckboxPositions = temp;
end;
And then to call it in the proc you could use:function string adjustCheckboxPositions(string fieldValue, array alpha(2) responses)
string temp;
do numeric ctr = 1 while ctr <= length(responses)
if pos(responses(ctr),fieldValue) then
temp[(ctr * 2 - 1):2] = responses(ctr);
else
temp[(ctr * 2 - 1):2] = "";
endif;
enddo;
adjustCheckboxPositions = temp;
end;
PROC MTST
array alpha (2) responses_2_1_3(6) = "01", "02", "03", "04","96","98";
$ = adjustCheckboxPositions($, responses_2_1_3);
array alpha (2) responses_2_1_3(6) = "01", "02", "03", "04","96","98";
$ = adjustCheckboxPositions($, responses_2_1_3);
Re: Multi select Options at their actual positions
Thanks for the help #Josh, I owe you one
-
- Posts: 1
- Joined: November 26th, 2018, 4:25 pm
Re: Multi select Options at their actual positions
Dear all,
Since 2012 I am using CSPro 4.1 for data collection.
Program was constructed in this program and that time we had 32 BIT in our laptops and PCs.
Now we bought new laptops and PCs but program does not support new devices due they are in 64 BIT.
I am asking is it any possibility to update program which I have in CSPro 4.1 in CSPro 7.1.3 or earlier version but to support our new devices or should I start from beginning to develop new program for data collection?
Thank you in advanced
Best regards and hope for your soon answers.
Since 2012 I am using CSPro 4.1 for data collection.
Program was constructed in this program and that time we had 32 BIT in our laptops and PCs.
Now we bought new laptops and PCs but program does not support new devices due they are in 64 BIT.
I am asking is it any possibility to update program which I have in CSPro 4.1 in CSPro 7.1.3 or earlier version but to support our new devices or should I start from beginning to develop new program for data collection?
Thank you in advanced
Best regards and hope for your soon answers.
Re: Multi select Options at their actual positions
CSPro is backwards compatible so you should be able to just open your 4.1 app in 7.1.
Next time please start a new topic rather than adding to an unrelated one.
Next time please start a new topic rather than adding to an unrelated one.
Re: Multi select Options at their actual positions
Dear Josh
The following errors are shown when I used your code to place "multiple select" options in their actual positions.
The code I just copied :
The following errors are shown when I used your code to place "multiple select" options in their actual positions.
Code: Select all
ERROR: Expecting left parenthesis '(' in a function call near line 9 in GLOBAL procedure
ERROR: PostProc already defined near line 2 in Q2_1_3 procedure
Code: Select all
PROC GLOBAL
function string adjustCheckboxPositions(string fieldValue, array alpha(2) responses)
string temp;
do numeric ctr = 1 while ctr <= length(responses)
if pos(responses(ctr),fieldValue) then
temp[(ctr * 2 - 1):2] = responses(ctr);
else
temp[(ctr * 2 - 1):2] = "";
endif;
enddo;
adjustCheckboxPositions = temp;
end;
PROC Q2_1_3
array alpha (2) responses_2_1_3(6) = "01", "02", "03", "04","96","98";
$ = adjustCheckboxPositions($, responses_2_1_3);
Re: Multi select Options at their actual positions
My apologies, it seems that passing an array to a function in this way does not work correctly in CSPro version 7.1. I have been using a beta version of 7.2 in which it does. The logic I posted for using a function will work in version 7.2 but not in version 7.1. For version 7.1 you will have to have separate logic for each multiple response field.