I am working with a lot of metadata, opening thousands of different db files: access, sas, dbf, and more. I wanted to add a feature that traps my errors not in the log file but in a new data set or on the master list of my list of files indicateing I had an error opening/connecting the LIBNAME. Does anyone have any starter code on this? Any help would be greatly apresheated for a new SAS guy (April/May2015). TIA. -KJ
ERROR: Connect: Could not find file 'D:\MyPath\MyMdb.MDB'.
ERROR: Error in the LIBNAME statement.
I suggest you check out the LIBNAME function which will allow you to trap return codes and error messages:
Is this remotly close?
for my program:
LIBNAME MYMDB ACCESS PATH="D:\MyDir\MyFile.MDB" access=readonly;
works and I can get my metadata.
when I try to addapt it to this web page sample:
%let mylib=c:\projects\May2015; %if %sysfunc(libname(new,&mylib)) %then %put %sysfunc(sysmsg());
I come up with this:
%if %sysfunc(libname('MYMDB', 'ACCESS', &myfile, 'readonly')) %then
and get this error:
ERROR: The %IF statement is not valid in open code.
I am not sure what to try, I have tryied adding and removing quotes on the arguments.
To use a %IF statement it must be inside a macro. Try this:
%macro Assign_Libname (MyFile = ); %if %sysfunc(libname('MYMDB', 'ACCESS', "&myfile", 'readonly')) %then %put %sysfunc(sysmsg()); %mend Assign_Libname; %Assign_Libname (MyFile = %str(D:\MyDir\MyFile.MDB));
Do it in a data step instead of using macro code. Especially if you want to create metadata.
data data_sources; infile cards truncover; length engine libref $8 rc 8 path msg $200 ; input engine $ path $200. ; libref='L'||put(_n_,Z7.); rc=libname(libref,path,engine,'access=readonly'); if rc then msg=sysmsg(); else msg='SUCCESS'; output; rc=libname(libref,' '); cards; base c:\downloads base c:\notfound xlsx c:\downloads\DSPI.xlsx ;;;;
287 data _null_; set ; put (_all_) (=/); run;
engine=base libref=L0000001 rc=0 path=c:\downloads msg=SUCCESS engine=base libref=L0000002 rc=-70008 path=c:\notfound msg=NOTE: Library L0000002 does not exist. engine=xlsx libref=L0000003 rc=0 path=c:\downloads\DSPI.xlsx msg=SUCCESS NOTE: There were 3 observations read from the data set WORK.DATA_SOURCES.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.