<?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: Returning Character from %eval in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Returning-Character-from-eval/m-p/558780#M155993</link>
    <description>&lt;P&gt;Macro variables are already character.&amp;nbsp; There is nothing you can do to make them character ... they already are.&amp;nbsp; You don't need quotes (and in fact shouldn't use quotes).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In some circumstances, there are tools that let you treat macro variables as numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All of this also means that you can simplify what you are trying to do dramatically:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let last_academic_period=201910;

%macro setFirstAndLastPeriod();
%let testing = %substr(&amp;amp;last_academic_period, 5, 2);
%put (&amp;amp;testing);
%if &amp;amp;testing = 10 or &amp;amp;testing = 20
%then %let first_academic_period = %eval(&amp;amp;last_academic_period - 490);
%else %if &amp;amp;testing = 30 %then 
%let first_academic_period = %eval(&amp;amp;last_academic_period - 420);
%put &amp;amp;first_academic_period;
%mend;
%setFirstAndLastPeriod();&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 14 May 2019 21:57:39 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2019-05-14T21:57:39Z</dc:date>
    <item>
      <title>Returning Character from %eval</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returning-Character-from-eval/m-p/558767#M155972</link>
      <description>&lt;P&gt;How can I set the value of&amp;nbsp;first_academic_period to character.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let last_academic_period='201910';&lt;/P&gt;
&lt;P&gt;%macro setFirstAndLastPeriod();&lt;BR /&gt;%let testing = %substr(&amp;amp;last_academic_period, 5, 2);&lt;BR /&gt;%put (&amp;amp;testing);&lt;BR /&gt;%if %substr(&amp;amp;last_academic_period, 5, 2) = '10' or %substr(&amp;amp;last_academic_period, 5, 2) = '20'&lt;BR /&gt;%then %let first_academic_period = input(%eval(&amp;amp;last_academic_period - 490), 6.);&lt;BR /&gt;%else %if %substr(&amp;amp;last_academic_period, 5, 2) = '30' %then &lt;BR /&gt;%let first_academic_period = input(%eval(&amp;amp;last_academic_period - 420), 6.);&lt;BR /&gt;%put &amp;amp;first_academic_period;&lt;BR /&gt;%mend;&lt;BR /&gt;%setFirstAndLastPeriod();&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2019 20:48:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returning-Character-from-eval/m-p/558767#M155972</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2019-05-14T20:48:42Z</dc:date>
    </item>
    <item>
      <title>Returning Character from %eval</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returning-Character-from-eval/m-p/558768#M155992</link>
      <description>&lt;P&gt;How can I set the value of&amp;nbsp;first_academic_period to character?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let last_academic_period='201910';&lt;/P&gt;
&lt;P&gt;%macro setFirstAndLastPeriod();&lt;BR /&gt;%let testing = %substr(&amp;amp;last_academic_period, 5, 2);&lt;BR /&gt;%put (&amp;amp;testing);&lt;BR /&gt;%if %substr(&amp;amp;last_academic_period, 5, 2) = '10' or %substr(&amp;amp;last_academic_period, 5, 2) = '20'&lt;BR /&gt;%then %let first_academic_period = input(%eval(&amp;amp;last_academic_period - 490), 6.);&lt;BR /&gt;%else %if %substr(&amp;amp;last_academic_period, 5, 2) = '30' %then &lt;BR /&gt;%let first_academic_period = input(%eval(&amp;amp;last_academic_period - 420), 6.);&lt;BR /&gt;%put &amp;amp;first_academic_period;&lt;BR /&gt;%mend;&lt;BR /&gt;%setFirstAndLastPeriod();&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2019 20:49:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returning-Character-from-eval/m-p/558768#M155992</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2019-05-14T20:49:25Z</dc:date>
    </item>
    <item>
      <title>Re: Returning Character from %eval</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returning-Character-from-eval/m-p/558780#M155993</link>
      <description>&lt;P&gt;Macro variables are already character.&amp;nbsp; There is nothing you can do to make them character ... they already are.&amp;nbsp; You don't need quotes (and in fact shouldn't use quotes).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In some circumstances, there are tools that let you treat macro variables as numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All of this also means that you can simplify what you are trying to do dramatically:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let last_academic_period=201910;

%macro setFirstAndLastPeriod();
%let testing = %substr(&amp;amp;last_academic_period, 5, 2);
%put (&amp;amp;testing);
%if &amp;amp;testing = 10 or &amp;amp;testing = 20
%then %let first_academic_period = %eval(&amp;amp;last_academic_period - 490);
%else %if &amp;amp;testing = 30 %then 
%let first_academic_period = %eval(&amp;amp;last_academic_period - 420);
%put &amp;amp;first_academic_period;
%mend;
%setFirstAndLastPeriod();&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 May 2019 21:57:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returning-Character-from-eval/m-p/558780#M155993</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-05-14T21:57:39Z</dc:date>
    </item>
    <item>
      <title>Re: Returning Character from %eval</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returning-Character-from-eval/m-p/558781#M155977</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5059"&gt;@DavidPhillips2&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First of all, please delete the second copy of your question (which you seem to have posted by mistake) to avoid confusion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Remember that macro variables always contain &lt;EM&gt;text&lt;/EM&gt;. So, in most cases there is no need for quotation marks. I think if you delete &lt;EM&gt;all&lt;/EM&gt; quotation marks and the likewise unnecessary (and syntactically incorrect) calls to the INPUT function (i.e., simply write&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;...&lt;/FONT&gt;=%eval(&lt;FONT face="arial,helvetica,sans-serif"&gt;...&lt;/FONT&gt;);&lt;/FONT&gt;) in your code, the result will be much closer to your expectation.&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2019 21:58:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returning-Character-from-eval/m-p/558781#M155977</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-05-14T21:58:02Z</dc:date>
    </item>
    <item>
      <title>Re: Returning Character from %eval</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returning-Character-from-eval/m-p/558785#M155980</link>
      <description>&lt;P&gt;It is generally a sub-optimal approach to macro coding to not pass values into a macro explicitly. Better would be&lt;/P&gt;
&lt;PRE&gt;%macro setFirstAndLastPeriod(last_academic_period);&lt;/PRE&gt;
&lt;P&gt;and call&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%setFirstAndLastPeriod(201920);&lt;/PRE&gt;
&lt;P&gt;If you want the First_academic_period value available outside of the macro you will need to declare it as %global or use a different approach making the macro more of macro function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%then %let first_academic_period = &lt;STRONG&gt;&lt;FONT color="#ff0000"&gt;input&lt;/FONT&gt;&lt;/STRONG&gt;(%eval(&amp;amp;last_academic_period - 490), 6.);&lt;/PRE&gt;
&lt;P&gt;Input is not a macro function so the above code is going to set the macro variable to the text "input(xxxxx, 6.)" for differing input values. Is that the intent?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this is a date manipulation you might consider moving it to data step code.&lt;/P&gt;
&lt;P&gt;What are the magic numbers 490 and 420 supposed to represent? And what is the expected output for 201910, 201920 and 201930?&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2019 22:43:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returning-Character-from-eval/m-p/558785#M155980</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-14T22:43:01Z</dc:date>
    </item>
    <item>
      <title>Re: Returning Character from %eval</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returning-Character-from-eval/m-p/558891#M156010</link>
      <description>&lt;P&gt;&lt;A id="link_8" class="lia-link-navigation lia-page-link lia-user-name-link" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954" target="_self"&gt;&lt;SPAN class="login-bold"&gt;Astounding&lt;/SPAN&gt;&lt;/A&gt;, thanks for your help&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 12:57:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returning-Character-from-eval/m-p/558891#M156010</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2019-05-15T12:57:21Z</dc:date>
    </item>
  </channel>
</rss>

