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

I have two matrices A and ALS; my goal is to merge rows from ALS matrix where visit = 18 with matrix A by the ID variable. Any tip on how to do it in IML?

 

image.png

 

image.png

1 ACCEPTED SOLUTION

Accepted Solutions
IanWakeling
Barite | Level 11

If there are no complications, so both matrices are sorted on ID, the set of IDs is the same in both, and ALS contains a visit 18 for every ID, then you could use the LOC function to find the rows in ALS that correspond to the visit 18s.

 

A = A || ALS[ loc(ALS[,3]=18), ];

For more complex cases it may be better to do the merging in a data step as also suggested.

View solution in original post

7 REPLIES 7
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13
/*
I have two matrices A and ALS; 
my goal is to merge rows from ALS matrix 
where visit = 18 with matrix A 
by the ID variable. 
Any tip on how to do it in IML?
*/
proc sort data=a out=a_sorted;
	by ID;
run;
proc sort data=als out=als_sorted;
	by ID;
run;
data want;
	merge a_sorted(in=ina)
	      als_sorted;
	 by ID;
	 if ina;
	 if visit=18;
run;
Reeza
Super User

@kaushik_patra wrote:

I have two matrices A and ALS; my goal is to merge rows from ALS matrix where visit = 18 with matrix A by the ID variable. Any tip on how to do it in IML?

 

image.png

 

image.png


You've posted this in the IML forum, are you using SAS/IML or SAS Base. Are they matrices in IML or data sets?

 

It looks like you have you're trying to score some data, so you may want to consider PROC PLM and/or SCORE or a SCORE statement within whatever procedure you used. 

IanWakeling
Barite | Level 11

If there are no complications, so both matrices are sorted on ID, the set of IDs is the same in both, and ALS contains a visit 18 for every ID, then you could use the LOC function to find the rows in ALS that correspond to the visit 18s.

 

A = A || ALS[ loc(ALS[,3]=18), ];

For more complex cases it may be better to do the merging in a data step as also suggested.

kaushik_patra
Obsidian | Level 7

Thank you.

Reeza
Super User

@kaushik_patra please don't mark your own answer as correct, mark the answer that helped you solve the issue.

kaushik_patra
Obsidian | Level 7
Sorry, it's a mistake. Is there any way to undo and mark the correct answer provided by IanWakeling as solution?
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

@kaushik_patra you can un-select the solution you chose and then reselect the answer that applies.

 

sas-innovate-white.png

🚨 Early Bird Rate Extended!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Lock in the best rate now before the price increases on April 1.

Register now!

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 7 replies
  • 2619 views
  • 3 likes
  • 4 in conversation