Hi Forum
Gregori, Josh
I have raw data that has many binary variables with value only 1 or 2. I = Yes and 2=No
I want to build them on CSPro Data Entry, but to one single Occurrence Variable (CSPro Dictionary Format)?
This is the example:
Q1: What is your favorite color (Multiple Answer):
1. Red
2. White
3. Black
4. Others
The Raw Data Case 2 :
Q1_1 = 1 (Yes)
Q1_2 = 2 (No)
Q1_3 = 1 (Yes)
Q1_4 = 1 (Yes)
I want to convert them as one Occurrence variable :
Q1 : 134 (on data entry only enter 134)
Please see the screenshot image.
Your help very appreciate
Yanin
Multiple Binary To One Occurrence Variance
Multiple Binary To One Occurrence Variance
- Attachments
-
- BinaryToOccurence.PNG (17.93 KiB) Viewed 5737 times
Re: Multiple Binary To One Occurrence Variance
This code hasn't been tested but I think something like this should work:
numeric nextEntry = 1;
if Q1_1 = 1 then
Q1(nextEntry) = 1;
nextEntry = nextEntry + 1;
endif;
if Q1_2 = 1 then
Q1(nextEntry) = 2;
nextEntry = nextEntry + 1;
endif;
if Q1_3 = 1 then
Q1(nextEntry) = 3;
nextEntry = nextEntry + 1;
endif;
if Q1_4 = 1 then
Q1(nextEntry) = 4;
nextEntry = nextEntry + 1;
endif;
if Q1_1 = 1 then
Q1(nextEntry) = 1;
nextEntry = nextEntry + 1;
endif;
if Q1_2 = 1 then
Q1(nextEntry) = 2;
nextEntry = nextEntry + 1;
endif;
if Q1_3 = 1 then
Q1(nextEntry) = 3;
nextEntry = nextEntry + 1;
endif;
if Q1_4 = 1 then
Q1(nextEntry) = 4;
nextEntry = nextEntry + 1;
endif;
Re: Multiple Binary To One Occurrence Variance
Thank you Josh.
I tried to put your code on my batch application but failed to compile.
Would you please take a look the attached file of my batch application
file: BinaryToOcc.zip.
Very thanks Josh
Yanin
I tried to put your code on my batch application but failed to compile.
Would you please take a look the attached file of my batch application
file: BinaryToOcc.zip.
Very thanks Josh
Yanin
- Attachments
-
- BinaryToOcc.zip
- (29.06 KiB) Downloaded 345 times
Re: Multiple Binary To One Occurrence Variance
You have put the code in the proc global and only declarations are allowed in global. Try putting it in the level proc instead (PROC RAW_LEVEL).
You will also need to set the occurrences for Q1 to 4 in your dictionary.
You will also need to set the occurrences for Q1 to 4 in your dictionary.
Re: Multiple Binary To One Occurrence Variance
Aha . Marvelous ! marvelous ! Josh
Its worked.
For forum who want to know the solution with code given by Josh: Please see the batch program BinaryToOcc2.zip attached.
Thank you Josh
Yanin
Its worked.
For forum who want to know the solution with code given by Josh: Please see the batch program BinaryToOcc2.zip attached.
Thank you Josh
Yanin
- Attachments
-
- BinaryToOcc2.zip
- (66.14 KiB) Downloaded 358 times