BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ullsokk
Pyrite | Level 9

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

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

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).

Kurt_Bremser
Super User

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.

Ullsokk
Pyrite | Level 9

Thansks, I did not know about cas spesific symput statements and %let beeing resolved beforehand. Got it working using the casl symput 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1549 views
  • 1 like
  • 2 in conversation