- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to check if the dataset is already loaded to cas using this code:
%let data= 'MyDataSet';
proc cas;
table.tableExists result =r / name="&data" caslib="MyCasLib";
print(r);
if r=0 then do;
print("table is not loaded");
%let loaded = 0;
end;
else ;
print("Table already loaded");
quit;
The code works if I hard code the table name, but not if I try to use a macro value, and enter "MyDataSet" in stead. From the log, I can see that the macro variable is not resolved when I try to use the macro variable &data
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
And your next mistake is this
%let loaded = 0;
Macro statements are resolved while the code is fetched for interpretation/compilation, so this statement is resolved before PROC CAS runs, and &loaded will be zero in all cases.
You have to use the CASL functions SYMPUT or SYMPUTX to conditionally set a macro variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Everything after the %LET up to the semicolon (except leading and trailing blanks) is stored in the macro variable, so your statement resolves to
table.tableExists result =r / name="'MyDataSet'" caslib="MyCasLib";
which is not correct syntax. Always keep in mind that the macro processor is a text generating/replacing engine, and you do not need quotes around strings, unless you explicitly want them later (which is usually not the case).
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
And your next mistake is this
%let loaded = 0;
Macro statements are resolved while the code is fetched for interpretation/compilation, so this statement is resolved before PROC CAS runs, and &loaded will be zero in all cases.
You have to use the CASL functions SYMPUT or SYMPUTX to conditionally set a macro variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thansks, I did not know about cas spesific symput statements and %let beeing resolved beforehand. Got it working using the casl symput