I don't know enough about Proc IML to tell if it allows you to replace a source table.
You've nicely commented your code and it doesn't say anywhere "write" or "update" - which is what's missing.
Here a link how such a write could look like:
https://blogs.sas.com/content/iml/2011/04/18/writing-data-from-a-matrix-to-a-sas-data-set.html
And here docu sample code how to update data:
Post it at IML forum. I remembered there is already a post like yours in IML forum.
Aren't you the same person ?
I don't have a matrix to test this on, but I think this ought to work
where = loc(m=-99 or m=99);
m[where]=.;
No loops needed (in general, you don't want to use loops in IML anyway, you want to use matrix commands; the only time you would use loops is if you are developing some sort of iterative algorithm)
If you receive values that you know are going to be set to missing, such as with an indicator code like this, you might consider reading the data into missing to begin with.
proc format library=work; invalue myvalues '99', '-99' = . ; run; /* reading raw data*/ data example; input v1 :myvalues. ; datalines; 1 2 9 99 -99 -45 45 ;
Another option would be use an assignment of special missing in the format like .Z (replace the . in the invalue with .Z )that would allow you to tell the difference between missing because no value was read or the missing set due to this rule. The value is still missing for purposes of calculations but can be printed or examined.
Why not post it at IML forum ? since it is IML question ? @Rick_SAS is there.
data example;
input v1 ;
v2=v1;
datalines;
1
2
9
99
-99
-45
45
;
proc iml;
use example;
read all var _all_ into x[c=vname];
close;
x[loc(x=99 | x=-99)]=.;
create want from x[c=vname];
append from x;
close;
quit;
As Paige and KSharp said, use the LOC function. However, never use a "naked LOC":
always check that at least one observation satisfied the search criterion.
missingIdx = loc(m=-99 | m=99);
if ncol(missingIdx)>0 then
m[where] = .;
I have merged the two separate threads into one thread.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.