BookmarkSubscribeRSS Feed
R_A_G_
Calcite | Level 5
Hello,

I am using IF Then statement to label my binary data by their combination. I have 3 binary variables which means 2**3=7 combination:
this is my data:
A B C
1 1 1
0 0 1
and so on

so, the first row will be combination 8, 2nd combination 1,....
Right now I am using IF Then statement which means 8 lines of "if then" how can I avoid this and use a shorter code?
thank you
5 REPLIES 5
RickM
Fluorite | Level 6
You could do something like...

comb=input(catx(put(A,1.),put(B,1.),put(C,1.)),binary3.);

Good luck!
R_A_G_
Calcite | Level 5
Thanks Rick,
it worked I replaced my code with yours (had to switch 1st statemment with the 2nd). Do you mind explaining what your code did.
Thanks again

this was my code(long:)):
IF SKILLS1=0 and SKILLS2=0 AND SKILLS3=1 THEN COMBINATION=1;
if SKILLS1=0 and SKILLS2=1 AND SKILLS3=0 THEN COMBINATION=2;
IF SKILLS1=0 and SKILLS2=1 AND SKILLS3=1 THEN COMBINATION=3;
IF SKILLS1=1 and SKILLS2=0 AND SKILLS3=0 THEN COMBINATION=4;
IF SKILLS1=1 and SKILLS2=0 AND SKILLS3=1 THEN COMBINATION=5;
IF SKILLS1=1 and SKILLS2=1 AND SKILLS3=0 THEN COMBINATION=6;
IF SKILLS1=1 and SKILLS2=1 AND SKILLS3=1 THEN COMBINATION=7;
RickM
Fluorite | Level 6
It basically concatenated the 0's and 1's into a string ('111', '101', '001', etc) and then that string was converted to a number based on the binary informat.

You could also have calculated the binary number from the individual variables.

comb=A*2**2+B*2**1+C*2**0;
R_A_G_
Calcite | Level 5
thank you so much
R.A.G.
Ksharp
Super User
It looks like you are doing convert binary into dec



[pre]
data _null_;
retain combination -1;
do skills1=0,1;
do skills2=0,1;
do skills3=0,1;
combination+1;
put (_all_) (:);
end;
end;
end;
run;
[/pre]





Ksharp

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 895 views
  • 0 likes
  • 3 in conversation