<?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: understanding %upcase() in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/understanding-upcase/m-p/865059#M341597</link>
    <description>&lt;P&gt;still can't get my head around it. Will come back after the exam. Hopefully this will not be tested in Advanced programming exam.&lt;/P&gt;</description>
    <pubDate>Sat, 18 Mar 2023 21:58:20 GMT</pubDate>
    <dc:creator>Nietzsche</dc:creator>
    <dc:date>2023-03-18T21:58:20Z</dc:date>
    <item>
      <title>understanding %upcase()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/understanding-upcase/m-p/865019#M341573</link>
      <description>&lt;P&gt;Hello, I am reading about the %upcase function of the Advanced Prep Guide 4e pg 308&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Nietzsche_0-1679114065622.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81745i9B27ECFAC17A22F8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Nietzsche_0-1679114065622.png" alt="Nietzsche_0-1679114065622.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let a=begin;
%let b=%nrstr(&amp;amp;a);&lt;BR /&gt;%put UPCASE produces: %upcase(&amp;amp;a);
%put UPCASE produces: %upcase(&amp;amp;b);&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;running the code produces&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Nietzsche_0-1679113004337.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81744i132CB276C8FF3FC1/image-size/large?v=v2&amp;amp;px=999" role="button" title="Nietzsche_0-1679113004337.png" alt="Nietzsche_0-1679113004337.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I think I understand why %upcase(&amp;amp;a) would resolves to "BEGIN". The logic I think&amp;nbsp;should be something like this&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;%upcase(&amp;amp;a)&amp;nbsp; &lt;STRONG&gt;→&lt;/STRONG&gt;&amp;nbsp; &amp;nbsp; %upcase(begin)&amp;nbsp; &amp;nbsp;&lt;STRONG&gt;→&lt;/STRONG&gt; &amp;nbsp; &amp;nbsp;BEGIN&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I don't understand why %upcase(&amp;amp;b) is not getting "BEGIN" as well.&lt;/P&gt;
&lt;P&gt;%upcase(&amp;amp;b) becomes&amp;nbsp;%upcase(%nrstr(&amp;amp;a)) as it refers to &amp;amp;b.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%nrstr(&amp;amp;a) masks the "&amp;amp;" trigger, so it becomes just &amp;amp;a.&lt;/P&gt;
&lt;P&gt;so it becomes %upcase(&amp;amp;a), which comes %upcase(begin) which should become BEGIN&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;%upcase(&amp;amp;b)&amp;nbsp; &lt;STRONG&gt;→&lt;/STRONG&gt;&amp;nbsp; &amp;nbsp; %upcase(%nrstr(&amp;amp;a))&amp;nbsp; &amp;nbsp;&lt;STRONG&gt;→&amp;nbsp;&lt;/STRONG&gt;%upcase(&amp;amp;a)&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;→&lt;/STRONG&gt;&amp;nbsp;%upcase(begin)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;STRONG&gt;→&amp;nbsp;&lt;/STRONG&gt;BEGIN&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I don't understand why %upcase(&amp;amp;b) resolves to lowercase "begin".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks in advance.&lt;/P&gt;</description>
      <pubDate>Sat, 18 Mar 2023 04:34:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/understanding-upcase/m-p/865019#M341573</guid>
      <dc:creator>Nietzsche</dc:creator>
      <dc:date>2023-03-18T04:34:40Z</dc:date>
    </item>
    <item>
      <title>Re: understanding %upcase()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/understanding-upcase/m-p/865021#M341574</link>
      <description>&lt;P&gt;It does not matter what case you use when referring to a macro variable.&amp;nbsp; So &amp;amp;A and &amp;amp;a both reference the same macro variable named A.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because the value of B is macro quoted the %UPCASE() function just converted the string &amp;amp;a to the string &amp;amp;A.&amp;nbsp; But since you used %UPCASE() instead of %QUPCASE() the macro quoting was removed so the reverence to A is resolved by the %PUT statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Mar 2023 05:18:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/understanding-upcase/m-p/865021#M341574</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-18T05:18:10Z</dc:date>
    </item>
    <item>
      <title>Re: understanding %upcase()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/understanding-upcase/m-p/865022#M341575</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;It does not matter what case you use when referring to a macro variable.&amp;nbsp; So &amp;amp;A and &amp;amp;a both reference the same macro variable named A.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because the value of B is macro quoted the %UPCASE() function just converted the string &amp;amp;a to the string &amp;amp;A.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Okay, is what your saying this?&lt;/P&gt;
&lt;P&gt;%upcase(&amp;amp;b) → %upcase(%nrstr(&amp;amp;a)) → %upcase(&amp;amp;a) → %upcase(&amp;amp;A)→ being&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if that is true, then why the first macro reference %upcase(&amp;amp;a) resolved to "BEGIN"?&lt;/P&gt;
&lt;P&gt;While the second macro variable reference %upcase(&amp;amp;b)&amp;nbsp; becomes %upcase(&amp;amp;a) resolves to "begin"?&lt;/P&gt;
&lt;P&gt;should they have the the same result as %upcase(&amp;amp;b) becomes exact %upcase(&amp;amp;a) mid step?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Mar 2023 05:49:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/understanding-upcase/m-p/865022#M341575</guid>
      <dc:creator>Nietzsche</dc:creator>
      <dc:date>2023-03-18T05:49:58Z</dc:date>
    </item>
    <item>
      <title>Re: understanding %upcase()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/understanding-upcase/m-p/865030#M341583</link>
      <description>&lt;P&gt;The first %UPCASE converts the &lt;EM&gt;contents&lt;/EM&gt; of macro variable a to upper case; the second %UPCASE gets the macro-quoted (because of the previous use of %NRSTR) string &amp;amp;a, and converts it to &amp;amp;A, which is then resolved by the %PUT to the original content of macro variable a, which is lowercase.&lt;/P&gt;</description>
      <pubDate>Sat, 18 Mar 2023 07:34:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/understanding-upcase/m-p/865030#M341583</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-03-18T07:34:18Z</dc:date>
    </item>
    <item>
      <title>Re: understanding %upcase()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/understanding-upcase/m-p/865059#M341597</link>
      <description>&lt;P&gt;still can't get my head around it. Will come back after the exam. Hopefully this will not be tested in Advanced programming exam.&lt;/P&gt;</description>
      <pubDate>Sat, 18 Mar 2023 21:58:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/understanding-upcase/m-p/865059#M341597</guid>
      <dc:creator>Nietzsche</dc:creator>
      <dc:date>2023-03-18T21:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: understanding %upcase()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/understanding-upcase/m-p/865061#M341598</link>
      <description>&lt;P&gt;The %NRSTR() delays the resolution of the macro variable reference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So %UPCASE(&amp;amp;a) first resolves the &amp;amp;a to being.&amp;nbsp; Then it does the %UPCASE() on the string being to get BEING.&lt;/P&gt;
&lt;P&gt;But %UPCASE(&amp;amp;b) first results the &amp;amp;b to &amp;amp;a (but with macro quoting).&amp;nbsp; So the upcase applies to just the letter a.&amp;nbsp; However the macro quoting is removed by the %upcase() fubction. So it is converting essentially %nrstr(&amp;amp;a) into plain old &amp;amp;A, which will resolve to&amp;nbsp; being .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you ever need to do anything near this complicated with the macro language you are using the wrong tool for the job.&amp;nbsp; If you really need to manipulate data, like strings, then use SAS code.&amp;nbsp; You can always store the result back into a macro variable if it will help with future code generation.&amp;nbsp; Although for complex code generation you are better off using SAS code for that also.&lt;/P&gt;</description>
      <pubDate>Sat, 18 Mar 2023 22:22:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/understanding-upcase/m-p/865061#M341598</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-18T22:22:30Z</dc:date>
    </item>
  </channel>
</rss>

