<?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 dataset modification by using variable values for the name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-dataset-modification-by-using-variable-values-for-the-name/m-p/302343#M270426</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm being tasked with updating a lot of SAS programs due to a change in Dataset name configuration on our servers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Traditonally a series of datasets were stored each month within their own databases. The specific datasets were given the same name within each database. So for example in Freeze_month1 there would be a dataset called Activ. For Freeze_month2 there would be a dataset called activ.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This meant that the same code could be run each month just by modifying the libname reference to point to Freeze_month1&amp;nbsp;or Freeze_month2.&lt;/P&gt;
&lt;P&gt;They are now storing all data within the same database but as activ_m1 or activ_m2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was hoping to create a variable containing the 'month' element of the dataset and append that to the 'activ' element.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the code would look something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;libname&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;DB1 odbc dsn=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'database'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%let&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; mnth ='M1'; &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; aa;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;set&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="2"&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;DB1.activ&amp;amp;mnth&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;This would then translate to DB1.activ_M1&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;I've tried using various quotes but without success.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;Any help would be appreciated as I'm using SAS9.4.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;Thanks.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 04 Oct 2016 13:58:50 GMT</pubDate>
    <dc:creator>Brian_lewis67</dc:creator>
    <dc:date>2016-10-04T13:58:50Z</dc:date>
    <item>
      <title>SAS dataset modification by using variable values for the name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-dataset-modification-by-using-variable-values-for-the-name/m-p/302343#M270426</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm being tasked with updating a lot of SAS programs due to a change in Dataset name configuration on our servers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Traditonally a series of datasets were stored each month within their own databases. The specific datasets were given the same name within each database. So for example in Freeze_month1 there would be a dataset called Activ. For Freeze_month2 there would be a dataset called activ.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This meant that the same code could be run each month just by modifying the libname reference to point to Freeze_month1&amp;nbsp;or Freeze_month2.&lt;/P&gt;
&lt;P&gt;They are now storing all data within the same database but as activ_m1 or activ_m2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was hoping to create a variable containing the 'month' element of the dataset and append that to the 'activ' element.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the code would look something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;libname&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;DB1 odbc dsn=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'database'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%let&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; mnth ='M1'; &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; aa;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;set&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="2"&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;DB1.activ&amp;amp;mnth&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;This would then translate to DB1.activ_M1&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;I've tried using various quotes but without success.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;Any help would be appreciated as I'm using SAS9.4.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;Thanks.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2016 13:58:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-dataset-modification-by-using-variable-values-for-the-name/m-p/302343#M270426</guid>
      <dc:creator>Brian_lewis67</dc:creator>
      <dc:date>2016-10-04T13:58:50Z</dc:date>
    </item>
    <item>
      <title>Re: SAS dataset modification by using variable values for the name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-dataset-modification-by-using-variable-values-for-the-name/m-p/302345#M270427</link>
      <description>&lt;P&gt;You need to examine the text which is generated from using macro, try this:&lt;/P&gt;
&lt;P&gt;%let mnth ='M1';&lt;/P&gt;
&lt;P&gt;%put db1.activ&amp;amp;mnth;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What this will show you is that the code you are generating looks like this:&lt;/P&gt;
&lt;P&gt;db1.activ'M1'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is invalid, first the quotes in the macro variable mess it up, and secondly you miss the underscore. &amp;nbsp;Change to:&lt;/P&gt;
&lt;P&gt;%let mnth=M1;&lt;/P&gt;
&lt;P&gt;%put db1.activ_&amp;amp;mnth.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And the dataset name will be generated correctly.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2016 14:08:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-dataset-modification-by-using-variable-values-for-the-name/m-p/302345#M270427</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-10-04T14:08:46Z</dc:date>
    </item>
    <item>
      <title>Re: SAS dataset modification by using variable values for the name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-dataset-modification-by-using-variable-values-for-the-name/m-p/302365#M270428</link>
      <description>&lt;P&gt;That worked perfectly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It was the single quotes that threw me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks very much for such a quick reply&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2016 15:13:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-dataset-modification-by-using-variable-values-for-the-name/m-p/302365#M270428</guid>
      <dc:creator>Brian_lewis67</dc:creator>
      <dc:date>2016-10-04T15:13:25Z</dc:date>
    </item>
  </channel>
</rss>

