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?
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.
/*
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;
@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?
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.
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.
Thank you.
@kaushik_patra please don't mark your own answer as correct, mark the answer that helped you solve the issue.
@kaushik_patra you can un-select the solution you chose and then reselect the answer that applies.
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.