BookmarkSubscribeRSS Feed
GregBond
Obsidian | Level 7

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.

4 REPLIES 4
LinusH
Tourmaline | Level 20

Attaching sample input data, and desired output will help understand your requirement better.

Data never sleeps
GregBond
Obsidian | Level 7

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%

Astounding
PROC Star

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.

Astounding
PROC Star

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.

sas-innovate-2024.png

Today is the last day to save with the early bird rate! Register today for just $695 - $100 off the standard rate.

 

Plus, pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 906 views
  • 2 likes
  • 3 in conversation