<?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: Resolve a macro variable value as its own macro variable to resolve in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Resolve-a-macro-variable-value-as-its-own-macro-variable-to/m-p/571937#M161365</link>
    <description>&lt;P&gt;Use 3 ampersands not 2.&lt;/P&gt;</description>
    <pubDate>Tue, 09 Jul 2019 02:04:42 GMT</pubDate>
    <dc:creator>WarrenKuhfeld</dc:creator>
    <dc:date>2019-07-09T02:04:42Z</dc:date>
    <item>
      <title>Resolve a macro variable value as its own macro variable to resolve</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolve-a-macro-variable-value-as-its-own-macro-variable-to/m-p/571935#M161363</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I am trying to take the result of a macro variable which itself is the name of a macro variable and get that to resolve to its value.&lt;/P&gt;&lt;P&gt;The macro&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Macro variable SegmentA will already have the value 100 */&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; SegmentA= 100;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*I pull the Segment values&amp;nbsp;I need from a dataset and use the SQL&amp;nbsp;INTO&amp;nbsp;to get a macro variable with the value of the segment*/&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; seg1= SegmentA;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;&amp;amp;seg1;&lt;/FONT&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/*this doesn't work*/ &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/*How do I get the value of seg1 (SegmentA) to resolve to its macro value (100)?*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*If you know how to get Seg1 to return 100, you don't need to look further below*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Actual Code*/&lt;/P&gt;&lt;P&gt;/*Here is more of the code so you can maybe see why I am trying to do this*/&lt;/P&gt;&lt;P&gt;/*The macros with the 'numeric' values have already been established upstream*/&lt;/P&gt;&lt;P&gt;/*The point of this is that I have a specific # of records I need to pull from each segmentation.&lt;/P&gt;&lt;P&gt;That number of records per segmentation is stored in a macro variable of the same name as the segmentation*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &lt;STRONG&gt;&lt;I&gt;Test&lt;/I&gt;&lt;/STRONG&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%local&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; i;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;Proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;SQL&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp; select&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;distinct&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; segmentation&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp; from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; p.seg &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp; where&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; segmentation &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;ne&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="3"&gt;' '&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp; order&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; segmentation&lt;/FONT&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp; select&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;distinct&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; segmentation &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;into&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; :s1 - :s&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;sqlobs.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp; from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; p.seg&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp; where&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; segmentation &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;ne&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="3"&gt;' '&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp; order&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; segmentation&lt;/FONT&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; i=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%to&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;sqlobs;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp; %put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; run# &amp;amp;i. of &amp;amp;sqlobs. for macro_container=&amp;amp;&amp;amp;s&amp;amp;i.;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp; %let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; mc= &amp;amp;&amp;amp;s&amp;amp;i;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/*Set ts=1 if the record is under the threshold for that segmentation*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;data&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; temp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; p.seg;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; _n_ &amp;lt;= &amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;mc.&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ts=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/*Also need to determine how to get this to resolve as an integer. Input(&amp;amp;mc.,8.) didn't work*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp;where&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; segmentation=&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%unquote&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%nrquote&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(%'&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;mc.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;%')); &lt;/FONT&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/*Limit to just 1 segmentation at a time*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;run&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/*Update the segmentation to segmentationvalue_overlimit if ts=0 from Temp because those are the records in the segmentation over the # limit I need*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;proc&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp; update&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; p.seg as a&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp; set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; segmentation=( select cats(segmentation,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'_overlimit'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) from temp b &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;where&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;&amp;nbsp; a.acc_id=b.acc_id and ts=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; )&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;quit&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;I&gt;Test&lt;/I&gt;&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2019 01:54:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolve-a-macro-variable-value-as-its-own-macro-variable-to/m-p/571935#M161363</guid>
      <dc:creator>BuildsStuff</dc:creator>
      <dc:date>2019-07-09T01:54:32Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve a macro variable value as its own macro variable to resolve</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolve-a-macro-variable-value-as-its-own-macro-variable-to/m-p/571937#M161365</link>
      <description>&lt;P&gt;Use 3 ampersands not 2.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2019 02:04:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolve-a-macro-variable-value-as-its-own-macro-variable-to/m-p/571937#M161365</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2019-07-09T02:04:42Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve a macro variable value as its own macro variable to resolve</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolve-a-macro-variable-value-as-its-own-macro-variable-to/m-p/571943#M161370</link>
      <description>&lt;P&gt;To expand what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16777"&gt;@WarrenKuhfeld&lt;/a&gt;&amp;nbsp;said.&lt;/P&gt;&lt;P&gt;When SAS sees an &amp;amp; the compiler starts looking for macro variables. But, if it sees two of them, it replaces them with one, then continues to look for more macro variables. When it is done with the first loop of the checking, it does it again to see if there are any "new" references.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, in your case:&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;amp;&amp;amp;&amp;amp;seg1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;SAS now translates &amp;amp;&amp;amp; -&amp;gt; &amp;amp; and&amp;nbsp;&amp;amp;seg1 -&amp;gt;&amp;nbsp;&lt;SPAN&gt;SegmentA.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Now we have:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;amp;&lt;SPAN&gt;SegmentA&lt;/SPAN&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS now does the last translation&amp;nbsp;&lt;FONT face="Courier New" size="3"&gt;&amp;amp;&lt;SPAN&gt;SegmentA -&amp;gt; 100.&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Now we have:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;100&lt;/SPAN&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;As we don't have any more macro variables, SAS looks at macro programs (anything with %). In this case %put. It runs that code and prints "100" to the log file.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2019 02:31:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolve-a-macro-variable-value-as-its-own-macro-variable-to/m-p/571943#M161370</guid>
      <dc:creator>heffo</dc:creator>
      <dc:date>2019-07-09T02:31:52Z</dc:date>
    </item>
  </channel>
</rss>

