turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- IF THEN STATEMENT

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-28-2011 01:34 PM

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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to R_A_G_

03-28-2011 01:56 PM

You could do something like...

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

Good luck!

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

Good luck!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to RickM

03-28-2011 02:06 PM

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;

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to R_A_G_

03-28-2011 02:43 PM

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;

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

comb=A*2**2+B*2**1+C*2**0;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to RickM

03-28-2011 06:25 PM

thank you so much

R.A.G.

R.A.G.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to R_A_G_

03-28-2011 09:25 PM

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

[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