<?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: Numeric to character conversion with substr and eval function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715342#M220940</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;How to tackle this?&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Maxim 33: Intelligent Data Makes for Intelligent Programs.&lt;/P&gt;
&lt;P&gt;By storing dates (and date-related values like quarters) as SAS dates, you enable yourself to make use of the plethora of tools that SAS provides for date values.&lt;/P&gt;</description>
    <pubDate>Fri, 29 Jan 2021 16:03:42 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-01-29T16:03:42Z</dc:date>
    <item>
      <title>Numeric to character conversion with substr and eval function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715229#M220910</link>
      <description>&lt;P&gt;I've a variable called 'mon_qtr'&amp;nbsp; which was numeric and it had values like,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;P&gt;and now this variable has been converted to character and it has values like,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;001&lt;/P&gt;
&lt;P&gt;002&lt;/P&gt;
&lt;P&gt;003&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When this variable was numeric, I used the below condition in where clause. As this variable has been converted to character now, I would like to know how to tweak this condition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;mon_qtr in (%substr(&amp;amp;Reportingdate1,5,2), %eval(%substr(&amp;amp;Reportingdate1,5,2)-1),%eval(%substr(&amp;amp;Reportingdate1,5,2)-2))&lt;/PRE&gt;
&lt;P&gt;Value of the macro variable 'Reportingdate1' will be like,&lt;/P&gt;
&lt;P&gt;%let Reportingdate1=20200331;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 11:55:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715229#M220910</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-01-29T11:55:20Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric to character conversion with substr and eval function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715232#M220911</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When this variable was numeric, I used the below condition in where clause. As this variable has been converted to character now, I would like to know how to tweak this condition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;mon_qtr in (%substr(&amp;amp;Reportingdate1,5,2), %eval(%substr(&amp;amp;Reportingdate1,5,2)-1),%eval(%substr(&amp;amp;Reportingdate1,5,2)-2))&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Don't convert it to character (or keep the numeric variable) and you now have working code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;More importantly, don't work with dates as character strings, SAS has built in many functions that make your life easier if you handle them as actual dates (which are numeric). As an example, when the month part of &amp;amp;reportingdate is 01, the second %eval gives you a month of 0, and the third %eval gives you a month of -1, is that what you want? Again, using SAS dates as actual numbers rather than characters, and using SAS date functions, avoids all of these problems, and when the month of &amp;amp;reportingdate is 01, these SAS functions know that the previous month was 12 and the month before that is 11.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 12:05:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715232#M220911</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-01-29T12:05:41Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric to character conversion with substr and eval function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715241#M220916</link>
      <description>&lt;P&gt;mon_qtr should be a complete date value, and the macro variable a raw date (Maxim 28). Then your condition is&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;intnx('month',&amp;amp;reportingdate1.,-2,'b') le mon_qtr le intnx('month',&amp;amp;reportingdate1.,0,'e')&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and it will work seamlessly across year boundaries.&lt;/P&gt;
&lt;P&gt;Make your data intelligent (Maxim 33).&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 12:33:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715241#M220916</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-01-29T12:33:32Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric to character conversion with substr and eval function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715262#M220919</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;mon_qtr is character data type with the values like,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;001&lt;/P&gt;
&lt;P&gt;002&lt;/P&gt;
&lt;P&gt;003&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 13:12:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715262#M220919</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-01-29T13:12:16Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric to character conversion with substr and eval function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715273#M220921</link>
      <description>&lt;P&gt;As per Business needs the variable mon_qtr has been already changed to character. Now I want to see how can I update the condition in where clause.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 13:52:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715273#M220921</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-01-29T13:52:44Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric to character conversion with substr and eval function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715275#M220922</link>
      <description>&lt;P&gt;Just replace &lt;FONT face="courier new,courier"&gt;mon_qtr&lt;/FONT&gt; by&lt;/P&gt;
&lt;PRE&gt;input(mon_qtr, 32.)&lt;/PRE&gt;
&lt;P&gt;in your WHERE condition. Then you're back to numeric "values like 1, 2, 3" and the rest of the code works as before.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 14:09:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715275#M220922</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-01-29T14:09:03Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric to character conversion with substr and eval function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715321#M220931</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;As per Business needs the variable mon_qtr has been already changed to character. Now I want to see how can I update the condition in where clause.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So you never run that program in January or February?&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 15:31:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715321#M220931</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-01-29T15:31:22Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric to character conversion with substr and eval function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715322#M220932</link>
      <description>I will execute the program at any time.&lt;BR /&gt;</description>
      <pubDate>Fri, 29 Jan 2021 15:34:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715322#M220932</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-01-29T15:34:13Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric to character conversion with substr and eval function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715326#M220934</link>
      <description>&lt;P&gt;Then it will fail in those two months, as it will calculate target months of 0 and -1, as already mentioned.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 15:36:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715326#M220934</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-01-29T15:36:36Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric to character conversion with substr and eval function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715336#M220936</link>
      <description>How to tackle this?&lt;BR /&gt;</description>
      <pubDate>Fri, 29 Jan 2021 15:58:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715336#M220936</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-01-29T15:58:13Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric to character conversion with substr and eval function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715338#M220937</link>
      <description>&lt;P&gt;You did not provide enough examples of MON_QTR values to understand if it is supposed to represent MONTH or QUARTER. The values 1 to 3 could be valid for either.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also you did not show any examples of non-positive values of MON_QTR, but your %EVAL() calculations could generate such values.&amp;nbsp; Does that mean when the month part of&amp;nbsp;Reportingdate is January that you only want to use data from January?&amp;nbsp; But when it is March you want to use data from January, February and March?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks like from your code that you expect MON_QTR to have values from -1 to 12.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that you can use the INPUT() function to convert values like '001' into the number 1.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 15:59:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715338#M220937</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-29T15:59:10Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric to character conversion with substr and eval function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715341#M220939</link>
      <description>Mon_Qtr value represent the values of months and it always positive.&lt;BR /&gt;&lt;BR /&gt;Value of reporting date will always be any one of quarter ending date.&lt;BR /&gt;</description>
      <pubDate>Fri, 29 Jan 2021 16:03:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715341#M220939</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-01-29T16:03:13Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric to character conversion with substr and eval function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715342#M220940</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;How to tackle this?&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Maxim 33: Intelligent Data Makes for Intelligent Programs.&lt;/P&gt;
&lt;P&gt;By storing dates (and date-related values like quarters) as SAS dates, you enable yourself to make use of the plethora of tools that SAS provides for date values.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 16:03:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715342#M220940</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-01-29T16:03:42Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric to character conversion with substr and eval function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715345#M220941</link>
      <description>I'm sorry if I was mistaken.&lt;BR /&gt;&lt;BR /&gt;Values of the macro variable will be any one of the quarter ending date. So&lt;BR /&gt;it will  run only for the months March, June,September and December&lt;BR /&gt;</description>
      <pubDate>Fri, 29 Jan 2021 16:06:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715345#M220941</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-01-29T16:06:13Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric to character conversion with substr and eval function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715366#M220947</link>
      <description>&lt;P&gt;So if the only input months are 3,6,9, and 12 then you current code will work.&amp;nbsp; All you need to do is modify it so the IN operator is comparing values with the same type.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;So either convert MON_QTR to a number.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let Reporting_Month=%substr(&amp;amp;Reportingdate1,5,2);
...
input(mon_qtr,32.) in (&amp;amp;reporting_month %eval(&amp;amp;reporting_month-1) %eval(&amp;amp;reporting_month-2))
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or compare it to character strings instead of numbers.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;mon_qtr in 
("%sysfunc(putn(&amp;amp;reporting_month,Z3.))"
 "%sysfunc(putn(&amp;amp;reporting_month-1,Z3.))"
 "%sysfunc(putn(&amp;amp;reporting_month-2,Z3.))"
)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Jan 2021 16:49:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715366#M220947</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-29T16:49:11Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric to character conversion with substr and eval function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715725#M221099</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; I got the error when I tried to implement the recommended solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1172                mon_qtr in
1173                ("%sysfunc(putn(%substr(&amp;amp;Reportingdate1,5,2),Z3.))"
SYMBOLGEN:  Macro variable REPORTINGDATE1 resolves to 20200331
1174                 "%sysfunc(putn(%eval(%substr(&amp;amp;Reportingdate1,5,2)-1),Z3.))"
SYMBOLGEN:  Macro variable REPORTINGDATE1 resolves to 20200331
1175                 "%sysfunc(putn(%eval(%substr(&amp;amp;Reportingdate1,5,2)-2),Z3.))")  &amp;amp;
SYMBOLGEN:  Macro variable REPORTINGDATE1 resolves to 20200331
ERROR: Expression using IN has components that are of different data types.
NOTE: The IN referred to may have been transformed from an OR to an IN at some point during PROC SQL WHERE clause optimization.&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Feb 2021 08:00:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715725#M221099</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-02-01T08:00:32Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric to character conversion with substr and eval function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715729#M221103</link>
      <description>&lt;P&gt;Seems your mon_qtr is numeric, but you compare it to character strings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is the old problem of not providing data in usable form (data step with datalines), which forces us to make guesses, and of not posting the&amp;nbsp;&lt;EM&gt;whole&lt;/EM&gt; code of a step, which would allow us to recreate your situation as is.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 08:36:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-to-character-conversion-with-substr-and-eval-function/m-p/715729#M221103</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-01T08:36:11Z</dc:date>
    </item>
  </channel>
</rss>

