01-15-2016 12:29 PM
I have 10 variables that are answered 0 or 1, and those who responded have the option to asnwer each question(variable). I would like to combine these variables into one variable "adapt"; however, when using 'if-then' statements there seems to be overlap and certain variables are losing repsonses. For example when I run a freq on adapt.impact.chib by itself the count is 153, but when i run it after creating thew 'newvar' variable, its count changes to 125. Thanks in advance for any insight!
"if adapt.impct.chib=1 then newvar=1
if adapt.impct.more.nca=1 then newvar=2"
01-15-2016 01:50 PM
The questions I would like to combine into one new variable
1) Many of my cosumters have left and gone to Chibuku depots. 15 10% var ID=(adapt.impct.more.nca)
2) I now have to brewq more Traditional Beer. 13 34% var ID=(adapt.impct.more.vars)
3) I have to brew more varieties of Tradtional Beer. 52 19% var ID=(adapt.impct.more.beer)
adapt.impct.more.nca adapt.impct.more.vars adapt.impct.more.beer
1 1 1
1 1 1
0 0 0
1 1 1
1 1 0
0 0 0
1 1 0...........
I would like to combine these questions into one variable (newvar), where the answer totals would be the same for each respective variable as they were for when they are run just by itself. Hope that makles sense, thanks!
Desired output for new var
Newvar yes(n) %
Many of my cosumters have left and gone to Chibuku depots. 15 10%
I now have to brewq more Traditional Beer. 13 34%
I have to brew more varieties of Tradtional Beer. 52 19%
01-15-2016 04:12 PM - edited 01-16-2016 03:27 PM
I'm not sure you could use one combined variable to get the report that you want. Why not get the report you want based on the data you already have? Something along these lines ...
proc tabulate data=have;
var q1 q2 q3;
tables var1 var2 var2, sum mean*f=percent9.2;
The code is untested, and may need slight debugging. But it should give you the results you want (at least for 3 variables).
01-15-2016 01:01 PM
Looking at your IF/THEN logic, it appears that you haven't thought through what values you would like to assign to your new variable. For example, you would be taking some "1" values and changing them to "2". No wonder you don't find as many "1" values as you expect.
Come back with a plan for what your new variable should look like. Once you have a good plan, IF/THEN statements are easy.