BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SassienFuté
Calcite | Level 5

Hello everyone,

 

Does someone know how to replace a series of conditions as below :

 

if toto ne 0 then a = '1'; else a = '0';
if tutu ne 0 than b = '1'; else b = '0';
if titi ne 0 then c = '1'; else c = '0';
if tata ne 0 than d = '1'; else d = '0';
if tete ne 0 than e = '1'; else e = '0';

 

Thank you very much and have a good journey

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

OK, so the statements are the same, only variables change.

Use arrays:

data have;
input toto tutu titi tata tete;
datalines;
1 1 0 1 0
;

data want;
set have;
array in {*} toto tutu titi tata tete;
array out {*} $ a b c d e;
do i = 1 to dim(in);
  out{i} = ifc(in{i} ne 0,'1','0');
end;
drop i;
run;

The ifc() function is a simplification of your if/then/else.

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

Please post a more descriptive sample of your code, so we can see the conditions. Right now I have no idea what you want to simplify.

SassienFuté
Calcite | Level 5
Thank for your message KurtBremser. I just modified my post.
Kurt_Bremser
Super User

OK, so the statements are the same, only variables change.

Use arrays:

data have;
input toto tutu titi tata tete;
datalines;
1 1 0 1 0
;

data want;
set have;
array in {*} toto tutu titi tata tete;
array out {*} $ a b c d e;
do i = 1 to dim(in);
  out{i} = ifc(in{i} ne 0,'1','0');
end;
drop i;
run;

The ifc() function is a simplification of your if/then/else.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 621 views
  • 3 likes
  • 2 in conversation