SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
Sanscrit_2prov
Obsidian | Level 7

I would like to compare every row of matrix x (let's say 200 by 29) with each row of matrix y (150,29) one at a time.

So for example row 1 in X compared to rows 1 to 150 in y  to see if they both elements equal 1. If yes, set new matrix to 1.

Something like below:

 

do i=1 to 200;

  do j=1 to 150;

does x[i,]=y[j,] ? if yes new matrix say z[i,}=1;

end;

end;

 

z would have 200 rows and 29 columns.

2 REPLIES 2
PaigeMiller
Diamond | Level 26

The question isn't clear.

 

So for example row 1 in X compared to rows 1 to 150 in y to see if they both elements equal 1.

 

What does "if they both elements equal 1" mean?

 

z would have 200 rows and 29 columns.

 

Wouldn't the result be (150*200)x1? 

--
Paige Miller
Ksharp
Super User

Post some data and output you want could better explain your question !!

 

 

proc iml;
x={1 0,
   0 1,
   1 1};
y={1 1,
   1 1};

z=j(nrow(x),1,.);
do i=1 to nrow(x);
  if all(x[i,]=y) then z[i]=1;
end;
print z;
quit;

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