I've been playing around with some code I found in a previous topic (https://communities.sas.com/t5/SAS-Programming/Finding-a-value-in-all-datasets-in-all-variables/m-p/426525#M105094). I'm looking at using PROC IML to perform data checks across a data library as it does seem to be pretty efficient at doing this. However, I'm getting an error but the code I have seems to be working.
proc iml;
dsn='work.'+datasets('work');
do i=1 to nrow(dsn);
use (dsn[i]);
read all var _char_ into x[c=vnames];
flag=(find(x,'DATASETS')^=0);
do j=1 to nrow(flag);
loc=loc(flag[j,]);
if ^isempty(loc) then do;
temp=vnames[loc];
vname=vname//temp;
obs=obs//repeat(j,nrow(temp));
table=table//repeat(dsn[i],nrow(temp));
end;
end;
close (dsn[i]);
end;
create want var {table vname obs};
append;
close;
quit;
proc print noobs;run;
I get a dataset out which shows me the datasets, variables and observation numbers for variables that contain "DATASETS". The problem is I get an error in the LOG:
42 proc iml;
NOTE: IML Ready
43 dsn='work.'+datasets('work');
44 do i=1 to nrow(dsn);
45 use (dsn[i]);
46 read all var _char_ into x[c=vnames];
47 flag=(find(x,'DATASETS')^=0);
48 do j=1 to nrow(flag);
49 loc=loc(flag[j,]);
50 if ^isempty(loc) then do;
51 temp=vnames[loc];
52 vname=vname//temp;
53 obs=obs//repeat(j,nrow(temp));
54 table=table//repeat(dsn[i],nrow(temp));
55 end;
56 end;
57 close (dsn[i]);
58 end;
NOTE: Module ISEMPTY loaded from the storage SASHELP.IMLMLIB.
ERROR: No character variables in the data set.
statement : READ at line 46 column 5
59
60 create want var {table vname obs};
61 append;
62 close;
NOTE: Closing WORK.WANT
NOTE: The data set WORK.WANT has 43 observations and 3 variables.
63 quit;
NOTE: Exiting IML.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IML used (Total process time):
real time 0.01 seconds
cpu time 0.03 seconds
Anyone got any ideas what is causing this error?
I like the potential for IML to allow me to look across multiple datasets for values as it appears to be a pretty code-efficient method.
Regards,
Lawrence
... View more