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

If the data like the following, 

a=1, 2, 3, 4   b=1, 2, 3, 4   c=1, 2, 3, 4.

if a=1 or b=1 or c=1 then d1=1; else d1=0;

if a=2 or b=2 or c=2 then d2=1; else d2=0;

if a=3 or b=3 or c=3 then d3=1; else d3=0;

if a=4 or b=4 or c=4 then d4=1; else d4=0;

So how to make the programs easier by Macro.

1 ACCEPTED SOLUTION

Accepted Solutions
3 REPLIES 3
Kurt_Bremser
Super User

No macro needed, use arrays and a DO loop:

data want;
set have;
array in {*} a b c;
array out {*} d1-d4;
do i = 1 to dim(out);
  out{i} = (whichn(i,of in{*}) > 0);
end;
drop i;
run;

 

Tom
Super User Tom
Super User

You really only need the one macro.

out{i} = (whichn(i,of a b c) > 0)

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 727 views
  • 1 like
  • 3 in conversation