<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: open() function unquotes values? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/open-function-unquotes-values/m-p/835278#M330232</link>
    <description>&lt;P&gt;See more recent discussion about the impact of macro quoting on arguments passed to %SYSFUNC().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I remember the logic right it basically required double quoting. Something like.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%nrstr(%nrstr(%something))&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 26 Sep 2022 20:05:12 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-09-26T20:05:12Z</dc:date>
    <item>
      <title>open() function unquotes values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/open-function-unquotes-values/m-p/82934#M17900</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;Short question: Why does the open() function apparently unquote macro variables.&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;340&amp;nbsp; %put %sysfunc(open&amp;nbsp; (in(where=(var="%nrstr(%Something)"))));&lt;/P&gt;&lt;P&gt;WARNING: Apparent invocation of macro SOMETHING not resolved.&lt;/P&gt;&lt;P&gt;0&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Compare the above result to the length() function, which does NOT unmask the value (expected behavior).&lt;/P&gt;&lt;P&gt;341&amp;nbsp; %put %sysfunc(length(in(where=(var="%nrstr(%Something)"))));&lt;/P&gt;&lt;P&gt;28&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In this simple case of course user could change the code to use single quotes to hide the percent sign: &lt;/P&gt;&lt;P&gt;&amp;nbsp; %put %sysfunc(open(in(where=(var='%Something')));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But wondering if people agree that it is odd that open() is unquoting, and if there is a way to prevent this.&amp;nbsp; It feels like a bug to me, does it to you?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Longer version/background:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This came up because an autocall library had a %nobs macro, something like:&lt;/P&gt;&lt;P&gt;%macro nobs(data);&amp;nbsp;&amp;nbsp; /*macro function in autocall library to return # obs in a dataset*/ &lt;/P&gt;&lt;P&gt;%local nobs dsid rc; &lt;/P&gt;&lt;P&gt;%let dsid=%sysfunc(open(&amp;amp;data)); &lt;/P&gt;&lt;P&gt;%let nobs=%sysfunc(attrn(&amp;amp;dsid,NLOBSF)); &lt;/P&gt;&lt;P&gt;%let rc=%sysfunc(close(&amp;amp;dsid)); &lt;/P&gt;&lt;P&gt;&amp;amp;nobs&lt;/P&gt;&lt;P&gt;%mend nobs;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;User wrote a macro like:&lt;/P&gt;&lt;P&gt;%macro report(data=,type=);&lt;/P&gt;&lt;P&gt;%if %nobs(&amp;amp;data(where=(type="&amp;amp;type")))=0 %then %do; &lt;/P&gt;&lt;P&gt;&amp;nbsp; data _null_;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; file print;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; put "There were no records in &amp;amp;data with type=&amp;amp;type"; &lt;/P&gt;&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%else %do; &lt;/P&gt;&lt;P&gt;&amp;nbsp; title1 "Printout of &amp;amp;data where Type=&amp;amp;Type"; &lt;/P&gt;&lt;P&gt;&amp;nbsp; proc print data=&amp;amp;data;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where type="&amp;amp;type";&lt;/P&gt;&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp; title1;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend report;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And got the warning message when they ran:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test; &lt;/P&gt;&lt;P&gt;input Year Type $14. Value; &lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;2001 AbsoluteChange 10&lt;/P&gt;&lt;P&gt;2002 AbsoluteChange 20&lt;/P&gt;&lt;P&gt;2003 AbsoluteChange 30&lt;/P&gt;&lt;P&gt;2001 %Change&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&lt;/P&gt;&lt;P&gt;2002 %Change&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&lt;/P&gt;&lt;P&gt;2003 %Change&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 15&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%report(data=test,type=%nrstr(%Change))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp; But I don't see how %nobs can be fixed to avoid this problem.&amp;nbsp; 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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;--Quentin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Apr 2012 14:21:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/open-function-unquotes-values/m-p/82934#M17900</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2012-04-13T14:21:20Z</dc:date>
    </item>
    <item>
      <title>Re: open() function unquotes values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/open-function-unquotes-values/m-p/835252#M330222</link>
      <description>&lt;P&gt;You can change your report code to use SYMGET in the argument constructed for the data parameter to nobs.&amp;nbsp; This will alleviate issues related to passing seemingly unmaskable characters in the chain of calls.&lt;/P&gt;
&lt;PRE&gt;%macro report(data=, type=);&lt;BR /&gt;  %if %nobs(&amp;amp;data(where=(type=symget('type'))))=0 %then %do;&lt;BR /&gt;...&lt;/PRE&gt;
&lt;P&gt;The autocall maintainer of NOBS() should SUPERQ the data parameter to avoid unwanted interpretations.&lt;/P&gt;
&lt;PRE&gt;%let dsid=%sysfunc(open(%superq(data)));&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 18:25:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/open-function-unquotes-values/m-p/835252#M330222</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2022-09-26T18:25:12Z</dc:date>
    </item>
    <item>
      <title>Re: open() function unquotes values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/open-function-unquotes-values/m-p/835267#M330229</link>
      <description>&lt;P&gt;Holy Necrothread Revival Batman!&amp;nbsp; The question was posed 10 years ago.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 19:44:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/open-function-unquotes-values/m-p/835267#M330229</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-09-26T19:44:55Z</dc:date>
    </item>
    <item>
      <title>Re: open() function unquotes values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/open-function-unquotes-values/m-p/835272#M330230</link>
      <description>&lt;P&gt;Maybe even longer... this feels like a question from a job I was at more than 10 years ago.&amp;nbsp; But it's possible I was writing about myself as the user, in which case maybe 10 years is believable...&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 19:52:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/open-function-unquotes-values/m-p/835272#M330230</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-09-26T19:52:40Z</dc:date>
    </item>
    <item>
      <title>Re: open() function unquotes values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/open-function-unquotes-values/m-p/835278#M330232</link>
      <description>&lt;P&gt;See more recent discussion about the impact of macro quoting on arguments passed to %SYSFUNC().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I remember the logic right it basically required double quoting. Something like.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%nrstr(%nrstr(%something))&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Sep 2022 20:05:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/open-function-unquotes-values/m-p/835278#M330232</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-26T20:05:12Z</dc:date>
    </item>
  </channel>
</rss>

