<?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: Concatenate a string to return the value of a Macro variable in proc SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-a-string-to-return-the-value-of-a-Macro-variable-in/m-p/876318#M346235</link>
    <description>The SYMGET function is what I needed. Another user suggested the same thing just before you did. Thank you for taking the time to reply.</description>
    <pubDate>Wed, 17 May 2023 20:12:43 GMT</pubDate>
    <dc:creator>GeorgeBonanza</dc:creator>
    <dc:date>2023-05-17T20:12:43Z</dc:date>
    <item>
      <title>Concatenate a string to return the value of a Macro variable in proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-a-string-to-return-the-value-of-a-Macro-variable-in/m-p/876305#M346230</link>
      <description>&lt;P&gt;Below is a simplified example of what I am trying to do.&amp;nbsp; I'd like to know if it is possible to replace the case statement with a concatenation of "DISCOUNT_" and the value of ID and then return the value of that macro variable.&amp;nbsp; For example, the first record of the HAVE dataset would first concatenate "DISCOUNT_" and "001" and then return 0.1, the value of DISCOUNT_001 variable.&amp;nbsp; Essentially, the equivalent of &amp;amp;DISCOUNT_001.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any insight is appreciated.&amp;nbsp; Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%let DISCOUNT_001 = 0.1;
%let DISCOUNT_002 = 0.05;

data HAVE;
	input ID $ QTY UNIT;
	datalines;
001 2 500
001 4 500
002 3 300
002 1 300
;
run;

proc sql; create table WANT as
	select ID, SUM(QTY * UNIT * (1 - case ID when "001" then &amp;amp;DISCOUNT_001 when "002" then &amp;amp;DISCOUNT_002 else 0 end)) as REVENUE
	from HAVE
	group by 1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 May 2023 19:07:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-a-string-to-return-the-value-of-a-Macro-variable-in/m-p/876305#M346230</guid>
      <dc:creator>GeorgeBonanza</dc:creator>
      <dc:date>2023-05-17T19:07:03Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate a string to return the value of a Macro variable in proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-a-string-to-return-the-value-of-a-Macro-variable-in/m-p/876316#M346232</link>
      <description>&lt;P&gt;Technically, you could, by SYMGET to resolve the macro variable when the code executes, e.g.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql; create table WANT as
	select ID, SUM(QTY * UNIT * (1 - input(symget(cats("Discount_",ID)),8.) )) as REVENUE
	from HAVE
	group by 1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But this would be an unusual way to do a look-up in SAS.&amp;nbsp; In SQL, you could consider joining on a table with the discount value for each ID.&amp;nbsp; Or another common way to do a lookup in SAS is with a format or informat, e.g.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
  invalue disc
  '001'=.1
  '002'=.05
  ;
run ;

proc sql; create table WANT as
	select ID, SUM(QTY * UNIT * ( 1 - input(ID,disc.) )) as REVENUE
	from HAVE
	group by 1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 May 2023 20:02:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-a-string-to-return-the-value-of-a-Macro-variable-in/m-p/876316#M346232</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-05-17T20:02:11Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate a string to return the value of a Macro variable in proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-a-string-to-return-the-value-of-a-Macro-variable-in/m-p/876317#M346233</link>
      <description>&lt;P&gt;SYMGET is the function I think you want:&lt;/P&gt;
&lt;PRE&gt;data HAVE;
	input ID $ QTY UNIT;
        z = symget(cats('DISCOUNT_',id));
	datalines;
001 2 500
001 4 500
002 3 300
002 1 300
;
run;
&lt;/PRE&gt;
&lt;P&gt;Though may take an extra step to get a numeric value as the result is character&lt;/P&gt;
&lt;P&gt;Maybe (as I'm not really sure what you expect as a result)&lt;/P&gt;
&lt;PRE&gt;proc sql; create table WANT as
	select ID, SUM(QTY * UNIT * (1 - input(symget(cats('DISCOUNT_',id)),8.))) as REVENUE
	from HAVE
	group by 1;
quit;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 May 2023 20:02:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-a-string-to-return-the-value-of-a-Macro-variable-in/m-p/876317#M346233</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-17T20:02:54Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate a string to return the value of a Macro variable in proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-a-string-to-return-the-value-of-a-Macro-variable-in/m-p/876318#M346235</link>
      <description>The SYMGET function is what I needed. Another user suggested the same thing just before you did. Thank you for taking the time to reply.</description>
      <pubDate>Wed, 17 May 2023 20:12:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-a-string-to-return-the-value-of-a-Macro-variable-in/m-p/876318#M346235</guid>
      <dc:creator>GeorgeBonanza</dc:creator>
      <dc:date>2023-05-17T20:12:43Z</dc:date>
    </item>
  </channel>
</rss>

