Page 1 of 1

Multiple Binary To One Occurrence Variance

Posted: May 24th, 2017, 3:36 am
by yanina
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

Re: Multiple Binary To One Occurrence Variance

Posted: May 24th, 2017, 4:48 am
by josh
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;

Re: Multiple Binary To One Occurrence Variance

Posted: May 24th, 2017, 12:19 pm
by yanina
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

Re: Multiple Binary To One Occurrence Variance

Posted: May 24th, 2017, 11:24 pm
by josh
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.

Re: Multiple Binary To One Occurrence Variance

Posted: May 26th, 2017, 2:34 am
by yanina
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 :D

Yanin