<?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: Manipulating criteria for where statement in macro variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Manipulating-criteria-for-where-statement-in-macro-variables/m-p/392006#M277718</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/134244"&gt;@ColeG&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;And yes, you're right it would be essentially as fast to change two dates instead of one but at this point I just kind of want to figure out how this works. Also, I use the yrmth variable in multiple locations and it's usually a date range so it would be updating six+ variables each month. Again, yeah, that's not a big deal. But it would be kind of cool to be able to do this with just one or two variables&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Multiple uses of the variable makes the parsing a little more valid. I will admit that I dislike the longish ugly macro code to such things in one call.&lt;/P&gt;
&lt;P&gt;Here's my take on placing the quotes into the macro variable. I think the comma in the year is a tad odd but then I speak no Teradata.&lt;/P&gt;
&lt;PRE&gt;%let  yrmth=201708; 

data _null_;
   y= input(substr("&amp;amp;yrmth",1,4),f4.);
   m= input(substr("&amp;amp;yrmth",5,2),f2.);
   ystr=cats("'",put(y,comma5.),"'");
   mstr=cats("'",m,"'");
   call symputx('year',ystr);
   call symputx('month',mstr);
run;

%put year=&amp;amp;year. month=&amp;amp;month.;&lt;/PRE&gt;</description>
    <pubDate>Wed, 30 Aug 2017 20:03:57 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-08-30T20:03:57Z</dc:date>
    <item>
      <title>Manipulating criteria for where statement in macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Manipulating-criteria-for-where-statement-in-macro-variables/m-p/391948#M277711</link>
      <description>&lt;P&gt;I am working on creating tables using proc sql. I need to update these tables monthly and would like to only change one %let statement at the beginning in order to accomplish this, however I am currently restricted by the data formats in the data warehouse.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The year is stored as (for example)&amp;nbsp;year_of_calendar = 2,017 and month is stored as month_of_year = 8. When referencing these two dates in the code, they must be contained in single quotes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is my code so far:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let yrmth=201708; /* update this every month */


/* never update these */
%let year=%unquote(%str(%'catx(',',substr(left(&amp;amp;yrmth),1,1),substr(left(&amp;amp;yrmth),2,3))%'));&lt;BR /&gt;	/* this is supposed to turn 201708 into '2,017' as year */
%let month=%unquote(%str(%'mod(&amp;amp;yrmth,100)%'));&lt;BR /&gt;	/* this is supposed to turn 201708 into '8' as month */

/* sql code that selects from only the month and year of interest */
proc sql;
select * from datawarehouse
 where year_of_calendar=&amp;amp;year. and month_of_year=&amp;amp;month;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;When I run this I get the following error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Teradata prepare: Syntax error, expected something like an 'ON' keyword between the word 'date_dim' and the 'date' keyword.&lt;/P&gt;&lt;P&gt;SQL statement was: select blah blah blah where&lt;/P&gt;&lt;P&gt;date.year_of_calendar='catx(',',substr(left(201708),1,1),substr(left(201708),2,3))' and date.month_of_year='mod(201708,100)'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The &amp;amp;yrmth variable is reading in correctly&amp;nbsp;but I can't the formulas themselves to work (I have verified that catx and mod statements do what I am expecting them to do when in a table, it is the %let statement that is giving me trouble).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 17:22:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Manipulating-criteria-for-where-statement-in-macro-variables/m-p/391948#M277711</guid>
      <dc:creator>ColeG</dc:creator>
      <dc:date>2017-08-30T17:22:36Z</dc:date>
    </item>
    <item>
      <title>Re: Manipulating criteria for where statement in macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Manipulating-criteria-for-where-statement-in-macro-variables/m-p/391952#M277712</link>
      <description>&lt;P&gt;Here is a list of functions that you are using, that macro language does not understand:&amp;nbsp; MOD, SUBSTR, CATX, LEFT&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could conceivably apply %SYSFUNC to each one of these, but that would be incredibly messy.&amp;nbsp; Instead, consider:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let year = %unquote(%str(%'%substr(&amp;amp;yrmth,1,1),%substr(&amp;amp;yrmth,2,3)%'));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When&amp;nbsp;you string text together, macro language just uses it.&amp;nbsp; You don't need CATX.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let month = %unquote(%str(%'%eval(&amp;amp;yrmth - &amp;amp;yrmth/100*100)%'));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%EVAL performs integer arithmetic, and macro language follows the usual order of operations so the subtraction is performed last.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 17:34:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Manipulating-criteria-for-where-statement-in-macro-variables/m-p/391952#M277712</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-08-30T17:34:01Z</dc:date>
    </item>
    <item>
      <title>Re: Manipulating criteria for where statement in macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Manipulating-criteria-for-where-statement-in-macro-variables/m-p/391957#M277713</link>
      <description>&lt;P&gt;Thank you for your help! However, when I try to run those statements I get errors.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the year statement, it says there are too few arguments for the substr statements (I don't know why).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the month statement, it says a character operand was found. Again, I don't know why, but is it because of the quotation marks?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 17:47:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Manipulating-criteria-for-where-statement-in-macro-variables/m-p/391957#M277713</guid>
      <dc:creator>ColeG</dc:creator>
      <dc:date>2017-08-30T17:47:10Z</dc:date>
    </item>
    <item>
      <title>Re: Manipulating criteria for where statement in macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Manipulating-criteria-for-where-statement-in-macro-variables/m-p/391958#M277714</link>
      <description>&lt;P&gt;It would help a lot if you showed a version of this code:&lt;/P&gt;
&lt;PRE&gt;proc sql;
select * from datawarehouse
 where year_of_calendar=&amp;amp;year. and month_of_year=&amp;amp;month;
quit;&lt;/PRE&gt;
&lt;P&gt;That works with none of the macro stuff at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will say that if I were dealing with only two parameters I do not see saving much time in updating&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let year = 2017;&lt;/P&gt;
&lt;P&gt;%let month = 8;&lt;/P&gt;
&lt;P&gt;instead of parsing out the bits from the string 201708.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 17:49:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Manipulating-criteria-for-where-statement-in-macro-variables/m-p/391958#M277714</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-08-30T17:49:52Z</dc:date>
    </item>
    <item>
      <title>Re: Manipulating criteria for where statement in macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Manipulating-criteria-for-where-statement-in-macro-variables/m-p/391963#M277715</link>
      <description>&lt;P&gt;I see what you mean about the error.&amp;nbsp; I can't explain it, but it's not too difficult to work around:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let yrmth = 201708;&lt;/P&gt;
&lt;P&gt;　&lt;/P&gt;
&lt;P&gt;%let year = %substr(&amp;amp;yrmth,1,1),%substr(&amp;amp;yrmth,2,3);&lt;/P&gt;
&lt;P&gt;%let year = %unquote(%str(%'&amp;amp;year%'));&lt;/P&gt;
&lt;P&gt;　&lt;/P&gt;
&lt;P&gt;Of course it's easier if you're allowed to use doublequotes instead of singlequotes.&amp;nbsp; Would Teradata accept that?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 17:56:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Manipulating-criteria-for-where-statement-in-macro-variables/m-p/391963#M277715</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-08-30T17:56:19Z</dc:date>
    </item>
    <item>
      <title>Re: Manipulating criteria for where statement in macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Manipulating-criteria-for-where-statement-in-macro-variables/m-p/391964#M277716</link>
      <description>&lt;P&gt;Without macros it would like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select * from datawarehouse&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; where year_of_calendar='2,017' and month_of_year='8';&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And yes, you're right it would be essentially as fast to change two dates instead of one but at this point I just kind of want to figure out how this works. Also, I use the yrmth variable in multiple locations and it's usually a date range so it would be updating six+ variables each month. Again, yeah, that's not a big deal. But it would be kind of cool to be able to do this with just one or two variables&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 17:56:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Manipulating-criteria-for-where-statement-in-macro-variables/m-p/391964#M277716</guid>
      <dc:creator>ColeG</dc:creator>
      <dc:date>2017-08-30T17:56:52Z</dc:date>
    </item>
    <item>
      <title>Re: Manipulating criteria for where statement in macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Manipulating-criteria-for-where-statement-in-macro-variables/m-p/391968#M277717</link>
      <description>&lt;P&gt;Awesome! Yes that worked, thank you so much! Double-quotes don't seem to work, unfortunately.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did the same thing with the month statement and the character operand error went away. So I think it probably was the quotes thing that led to the errors.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 18:09:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Manipulating-criteria-for-where-statement-in-macro-variables/m-p/391968#M277717</guid>
      <dc:creator>ColeG</dc:creator>
      <dc:date>2017-08-30T18:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: Manipulating criteria for where statement in macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Manipulating-criteria-for-where-statement-in-macro-variables/m-p/392006#M277718</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/134244"&gt;@ColeG&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;And yes, you're right it would be essentially as fast to change two dates instead of one but at this point I just kind of want to figure out how this works. Also, I use the yrmth variable in multiple locations and it's usually a date range so it would be updating six+ variables each month. Again, yeah, that's not a big deal. But it would be kind of cool to be able to do this with just one or two variables&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Multiple uses of the variable makes the parsing a little more valid. I will admit that I dislike the longish ugly macro code to such things in one call.&lt;/P&gt;
&lt;P&gt;Here's my take on placing the quotes into the macro variable. I think the comma in the year is a tad odd but then I speak no Teradata.&lt;/P&gt;
&lt;PRE&gt;%let  yrmth=201708; 

data _null_;
   y= input(substr("&amp;amp;yrmth",1,4),f4.);
   m= input(substr("&amp;amp;yrmth",5,2),f2.);
   ystr=cats("'",put(y,comma5.),"'");
   mstr=cats("'",m,"'");
   call symputx('year',ystr);
   call symputx('month',mstr);
run;

%put year=&amp;amp;year. month=&amp;amp;month.;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Aug 2017 20:03:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Manipulating-criteria-for-where-statement-in-macro-variables/m-p/392006#M277718</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-08-30T20:03:57Z</dc:date>
    </item>
  </channel>
</rss>

