04-13-2012 10:21 AM
Short question: Why does the open() function apparently unquote macro variables.
340 %put %sysfunc(open (in(where=(var="%nrstr(%Something)"))));
WARNING: Apparent invocation of macro SOMETHING not resolved.
The user has quoted the value because %Something is a text string, not a macro invocation, but the open function is unmasking it, producing the warning message. (The result is still fine).
Compare the above result to the length() function, which does NOT unmask the value (expected behavior).
341 %put %sysfunc(length(in(where=(var="%nrstr(%Something)"))));
In this simple case of course user could change the code to use single quotes to hide the percent sign:
But wondering if people agree that it is odd that open() is unquoting, and if there is a way to prevent this. It feels like a bug to me, does it to you?
This came up because an autocall library had a %nobs macro, something like:
%macro nobs(data); /*macro function in autocall library to return # obs in a dataset*/
%local nobs dsid rc;
User wrote a macro like:
%if %nobs(&data(where=(type="&type")))=0 %then %do;
put "There were no records in &data with type=&type";
title1 "Printout of &data where Type=&Type";
proc print data=&data;
And got the warning message when they ran:
input Year Type $14. Value;
2001 AbsoluteChange 10
2002 AbsoluteChange 20
2003 AbsoluteChange 30
2001 %Change 5
2002 %Change 10
2003 %Change 15
So the user deduces that it is %nobs which is unmasking the percent sign in %Change, and calls the guy who maintains the autocall library and asks him to fix it. But I don't see how %nobs can be fixed to avoid this problem. Given the number of %nobs (and other) macro functions that are floating around autocall libraries that use the open function, was wondering if anyone had a good fix. If not, I guess I'm stuck adding a limitation to every macro that uses the open() function to say that it will unquote values, and telling the user to redesign %report.