<?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 how to refer to a variable using let in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-refer-to-a-variable-using-let/m-p/293702#M61198</link>
    <description>&lt;P&gt;Dear experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;givend the following fata:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;data test;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;input segment: $12. jan: 10. feb: 10. mar: 10.;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;datalines;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;A 150 200 155&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;B 170 150 200&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;and given the following output:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;proc sql; create table test2 as select&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;segment, sum(feb) as sum_feb&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;from test group by 1 ;quit;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;I would like to get the same using the following reference:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;%let var=feb;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;proc sql; create table test3 as select&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;segment, sum('&amp;amp;var') as sum_&amp;amp;var&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;from test group by 1 ;quit;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;but as you can see it does not work. Any ideas? Thanks, SH.&lt;/P&gt;</description>
    <pubDate>Wed, 24 Aug 2016 13:24:53 GMT</pubDate>
    <dc:creator>Sir_Highbury</dc:creator>
    <dc:date>2016-08-24T13:24:53Z</dc:date>
    <item>
      <title>how to refer to a variable using %let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-refer-to-a-variable-using-let/m-p/293703#M61194</link>
      <description>&lt;P&gt;Dear experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;given the following data:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;data test;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;input segment: $12. jan: 10. feb: 10. mar: 10.;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;datalines;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;A 150 200 155&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;B 170 150 200&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;and given the following output:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;proc sql; create table test2 as select&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;segment, sum(feb) as sum_feb&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;from test group by 1 ;quit;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;I would like to get the same using the following reference:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;%let var=feb;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;proc sql; create table test3 as select&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;segment, sum('&amp;amp;var') as sum_&amp;amp;var&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;from test group by 1 ;quit;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;but as you can see it does not work. Any ideas? Thanks, SH.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2016 13:26:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-refer-to-a-variable-using-let/m-p/293703#M61194</guid>
      <dc:creator>Sir_Highbury</dc:creator>
      <dc:date>2016-08-24T13:26:42Z</dc:date>
    </item>
    <item>
      <title>how to refer to a variable using let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-refer-to-a-variable-using-let/m-p/293702#M61198</link>
      <description>&lt;P&gt;Dear experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;givend the following fata:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;data test;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;input segment: $12. jan: 10. feb: 10. mar: 10.;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;datalines;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;A 150 200 155&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;B 170 150 200&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;and given the following output:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;proc sql; create table test2 as select&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;segment, sum(feb) as sum_feb&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;from test group by 1 ;quit;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;I would like to get the same using the following reference:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;%let var=feb;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;proc sql; create table test3 as select&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;segment, sum('&amp;amp;var') as sum_&amp;amp;var&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;from test group by 1 ;quit;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;but as you can see it does not work. Any ideas? Thanks, SH.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2016 13:24:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-refer-to-a-variable-using-let/m-p/293702#M61198</guid>
      <dc:creator>Sir_Highbury</dc:creator>
      <dc:date>2016-08-24T13:24:53Z</dc:date>
    </item>
    <item>
      <title>Re: how to refer to a variable using %let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-refer-to-a-variable-using-let/m-p/293706#M61195</link>
      <description>&lt;P&gt;&lt;EM&gt;proc sql; &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp;create table test2 as select&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; segment, sum(feb) as sum_feb &lt;STRONG&gt;into:seg&lt;/STRONG&gt;,&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;from test group by segment ; &amp;nbsp; /* 1 means segment by now it is more readable */&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;quit;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;then you can use&lt;STRONG&gt; &amp;amp;seg &lt;/STRONG&gt;to get the sum of FEB per SEGment;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;I haven't check it, so better run and check.&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2016 13:32:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-refer-to-a-variable-using-let/m-p/293706#M61195</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-08-24T13:32:23Z</dc:date>
    </item>
    <item>
      <title>Re: how to refer to a variable using %let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-refer-to-a-variable-using-let/m-p/293709#M61196</link>
      <description>&lt;P&gt;variable names in a SQL select must not be enclosed in quotes. Text in quotes is considered a string literal.&lt;/P&gt;
&lt;P&gt;Therefore do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input segment: $12. jan: 10. feb: 10. mar: 10.;
datalines;
A 150 200 155
B 170 150 200
;
run;

%let var=feb;

proc sql;
create table test3 as select
segment, sum(&amp;amp;var) as sum_&amp;amp;var
from test group by 1;
quit;

proc print noobs;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;getting this result:&lt;/P&gt;
&lt;PRE&gt;segment    sum_feb

   A         200  
   B         150  
&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;16         data test;
17         input segment: $12. jan: 10. feb: 10. mar: 10.;
18         datalines;

NOTE: The data set WORK.TEST has 2 observations and 4 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.00 seconds
      
21         ;

22         run;
23         
24         %let var=feb;
25         
26         proc sql;
27         create table test3 as select
28         segment, sum(&amp;amp;var) as sum_&amp;amp;var
29         from test group by 1;
NOTE: Table WORK.TEST3 created, with 2 rows and 2 columns.

30         quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.03 seconds
      cpu time            0.00 seconds
      

31         
32         proc print noobs;
33         run;

NOTE: There were 2 observations read from the data set WORK.TEST3.
NOTE: The PROCEDURE PRINT printed page 1.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.04 seconds
      cpu time            0.01 seconds
&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Aug 2016 13:39:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-refer-to-a-variable-using-let/m-p/293709#M61196</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-08-24T13:39:42Z</dc:date>
    </item>
    <item>
      <title>Re: how to refer to a variable using %let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-refer-to-a-variable-using-let/m-p/293710#M61197</link>
      <description>&lt;P&gt;Literally replace every word of FEB with &amp;amp;var&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If in the middle of text use a period at the end to tell SAS it's the end of the macro variable.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2016 13:40:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-refer-to-a-variable-using-let/m-p/293710#M61197</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-08-24T13:40:38Z</dc:date>
    </item>
  </channel>
</rss>

