Multiple Binary To One Occurrence Variance

Discussions about tools to complement CSPro data processing
Post Reply
yanina
Posts: 60
Joined: October 31st, 2016, 9:37 am

Multiple Binary To One Occurrence Variance

Post 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
You do not have the required permissions to view the files attached to this post.
josh
Posts: 2403
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Multiple Binary To One Occurrence Variance

Post 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;
yanina
Posts: 60
Joined: October 31st, 2016, 9:37 am

Re: Multiple Binary To One Occurrence Variance

Post 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
You do not have the required permissions to view the files attached to this post.
josh
Posts: 2403
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Multiple Binary To One Occurrence Variance

Post 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.
yanina
Posts: 60
Joined: October 31st, 2016, 9:37 am

Re: Multiple Binary To One Occurrence Variance

Post 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
You do not have the required permissions to view the files attached to this post.
Post Reply