<?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 SAS Variable from Macro Date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Variable-from-Macro-Date/m-p/289767#M59865</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a SAS dataset which contains monthly customer information (variable examples below).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Customer &amp;nbsp; Date &amp;nbsp; Jan16 &amp;nbsp; Feb16 &amp;nbsp; Mar16 &amp;nbsp; Apr16 .....................&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For a SAS project I have to input the reporting date to be used to restrict the dataset (&amp;amp;mon. 01Jun2016 for example).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;CREATE TABLE TEST AS&lt;/P&gt;&lt;P&gt;SELECT *&lt;/P&gt;&lt;P&gt;FROM HAVE&amp;nbsp;&lt;/P&gt;&lt;P&gt;WHERE DATE &amp;lt;= "&amp;amp;mon."d;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to use this reporting date within the where clause of a step rather then inputting manually. For example for 01Jun2016 variable I want the following step using JUN2016:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;CREATE TABLE WANT AS&lt;/P&gt;&lt;P&gt;SELECT *&lt;/P&gt;&lt;P&gt;FROM HAVE&lt;/P&gt;&lt;P&gt;WHERE JUN2016 = .;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I turn the inputted prompt character into a variable without the need for manual intervention? I hope I have explained it clearly!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 05 Aug 2016 10:59:18 GMT</pubDate>
    <dc:creator>mk131190</dc:creator>
    <dc:date>2016-08-05T10:59:18Z</dc:date>
    <item>
      <title>SAS Variable from Macro Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Variable-from-Macro-Date/m-p/289767#M59865</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a SAS dataset which contains monthly customer information (variable examples below).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Customer &amp;nbsp; Date &amp;nbsp; Jan16 &amp;nbsp; Feb16 &amp;nbsp; Mar16 &amp;nbsp; Apr16 .....................&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For a SAS project I have to input the reporting date to be used to restrict the dataset (&amp;amp;mon. 01Jun2016 for example).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;CREATE TABLE TEST AS&lt;/P&gt;&lt;P&gt;SELECT *&lt;/P&gt;&lt;P&gt;FROM HAVE&amp;nbsp;&lt;/P&gt;&lt;P&gt;WHERE DATE &amp;lt;= "&amp;amp;mon."d;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to use this reporting date within the where clause of a step rather then inputting manually. For example for 01Jun2016 variable I want the following step using JUN2016:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;CREATE TABLE WANT AS&lt;/P&gt;&lt;P&gt;SELECT *&lt;/P&gt;&lt;P&gt;FROM HAVE&lt;/P&gt;&lt;P&gt;WHERE JUN2016 = .;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I turn the inputted prompt character into a variable without the need for manual intervention? I hope I have explained it clearly!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Aug 2016 10:59:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Variable-from-Macro-Date/m-p/289767#M59865</guid>
      <dc:creator>mk131190</dc:creator>
      <dc:date>2016-08-05T10:59:18Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Variable from Macro Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Variable-from-Macro-Date/m-p/289768#M59866</link>
      <description>&lt;P&gt;First of all, this example illustrates the disadvantages of a wide vs. a long dataset structure. Putting data (the dates) into structure (variable names) only makes your tasks harder.&lt;/P&gt;
&lt;P&gt;So the best solution is transposing your dataset into long format and then use the macro variable from the prompt in a where condition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OTOH, you can easily use a macro variable as a variable name:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date=01jun2016;
%let mon=%substr(&amp;amp;date,3);

proc sql;
create table want as select *
from have
where &amp;amp;mon = .
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Aug 2016 11:05:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Variable-from-Macro-Date/m-p/289768#M59866</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-08-05T11:05:35Z</dc:date>
    </item>
  </channel>
</rss>

