Hi all,
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"
adapt.impct.chib.
adapt.impct.more.nca.
adapt.impct.more.vars.
adapt.impct.chib.scrt.
ADAPT.IMPCT.QUAL.
ADAPT.IMPCT.LESS.SALE.
ADAPT.IMPCT.VARS.SCRT.
ADAPT.IMPCT.CRED.
ADAPT.IMPCT.SUP.
ADAPT.IMPCT.OTR.INC.
Attaching sample input data, and desired output will help understand your requirement better.
Hi All,
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%
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;
run;
The code is untested, and may need slight debugging. But it should give you the results you want (at least for 3 variables).
Good luck.
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.