<?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: %Eval with %Str in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Eval-with-Str/m-p/801692#M315525</link>
    <description>&lt;P&gt;Generally, it is a poor idea to have the values of macro variables enclosed in quotes or double-quotes. I'd recommend you not do that, and then there's no issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let academicPeriods = %eval(&amp;amp;firstAcademicPeriod +100);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you absolutely must have the result in double-quotes (why?), then its still relatively simple to do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let academicPeriods = "%eval(&amp;amp;firstAcademicPeriod +100)";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But really, don't put numbers such as 201910, which is the output of your calculation, in quotes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just to complete everything here, the problem is NOT %eval doesn't play well with %str.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 11 Mar 2022 17:48:58 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-03-11T17:48:58Z</dc:date>
    <item>
      <title>%Eval with %Str</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Eval-with-Str/m-p/801685#M315523</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let firstAcademicPeriod=201810;
%let academicPeriods = %str("%eval(&amp;amp;firstAcademicPeriod +100)");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I'm trying to use the eval function and return it with quotes around it.&amp;nbsp; It looks like %str and %eval do not play nice with each other.&amp;nbsp; Am I missing something here?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2022 15:49:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Eval-with-Str/m-p/801685#M315523</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2022-03-11T15:49:47Z</dc:date>
    </item>
    <item>
      <title>Re: %Eval with %Str</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Eval-with-Str/m-p/801692#M315525</link>
      <description>&lt;P&gt;Generally, it is a poor idea to have the values of macro variables enclosed in quotes or double-quotes. I'd recommend you not do that, and then there's no issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let academicPeriods = %eval(&amp;amp;firstAcademicPeriod +100);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you absolutely must have the result in double-quotes (why?), then its still relatively simple to do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let academicPeriods = "%eval(&amp;amp;firstAcademicPeriod +100)";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But really, don't put numbers such as 201910, which is the output of your calculation, in quotes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just to complete everything here, the problem is NOT %eval doesn't play well with %str.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2022 17:48:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Eval-with-Str/m-p/801692#M315525</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-11T17:48:58Z</dc:date>
    </item>
    <item>
      <title>Re: %Eval with %Str</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Eval-with-Str/m-p/801694#M315527</link>
      <description>&lt;P&gt;Try the quote function instead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let firstAcademicPeriod=201810;
%let academicPeriods = %sysfunc(quote(%sysevalf(&amp;amp;firstAcademicPeriod +100)));
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Mar 2022 16:07:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Eval-with-Str/m-p/801694#M315527</guid>
      <dc:creator>ChanceTGardener</dc:creator>
      <dc:date>2022-03-11T16:07:05Z</dc:date>
    </item>
    <item>
      <title>Re: %Eval with %Str</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Eval-with-Str/m-p/801698#M315528</link>
      <description>&lt;P&gt;Why would you want to macro quote a string like:&lt;/P&gt;
&lt;PRE&gt;"201910"&lt;/PRE&gt;
&lt;P&gt;Remove the %STR() macro function.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2022 16:18:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Eval-with-Str/m-p/801698#M315528</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-11T16:18:50Z</dc:date>
    </item>
    <item>
      <title>Re: %Eval with %Str</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Eval-with-Str/m-p/801715#M315536</link>
      <description>&lt;P&gt;I'm creating dynamic headers for a 500 page SAS output to PDF report.&amp;nbsp; The macro is used to keep the amount of repetitive code down.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2022 17:59:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Eval-with-Str/m-p/801715#M315536</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2022-03-11T17:59:31Z</dc:date>
    </item>
    <item>
      <title>Re: %Eval with %Str</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Eval-with-Str/m-p/801737#M315543</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*This works*/
%let defineAnalysis1 = %str (
define _2017_18 / analysis sum '2017-18';
define _2018_19 / analysis sum '2018-19';
define _2019_20 / analysis sum '2019-20';
define _2020_21 / analysis sum '2020-21';
define _2021_22 / analysis sum '2021-22';
);

%let fAcadP=201810;
%let fAcadYS=2017;
%let fAcadYE=18;

/*earlier I used %str to execute the block as a set.  Is there something similar I can use?*/
%let defineAnalysis1 = 
define _&amp;amp;fAcadYS._&amp;amp;fAcadYE. / analysis sum "_&amp;amp;fAcadYS.-&amp;amp;fAcadYE.";
define _%eval(&amp;amp;fAcadYS. +1)_%eval(&amp;amp;fAcadYE.+1) / analysis sum "_%eval(&amp;amp;fAcadYS. +1)_%eval(&amp;amp;fAcadYE.+1)";
define _%eval(&amp;amp;fAcadYS. +2)_%eval(&amp;amp;fAcadYE.+2) / analysis sum "_%eval(&amp;amp;fAcadYS. +2)_%eval(&amp;amp;fAcadYE.+2)";
define _%eval(&amp;amp;fAcadYS. +3)_%eval(&amp;amp;fAcadYE.+3) / analysis sum "_%eval(&amp;amp;fAcadYS. +3)_%eval(&amp;amp;fAcadYE.+3)";
define _%eval(&amp;amp;fAcadYS. +4)_%eval(&amp;amp;fAcadYE.+4) / analysis sum "_%eval(&amp;amp;fAcadYS. +4)_%eval(&amp;amp;fAcadYE.+4)";

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Mar 2022 20:44:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Eval-with-Str/m-p/801737#M315543</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2022-03-11T20:44:45Z</dc:date>
    </item>
    <item>
      <title>Re: %Eval with %Str</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Eval-with-Str/m-p/801738#M315544</link>
      <description>&lt;P&gt;Why not just put the %str() (or perhaps %nrstr() instead) around the semi-colons since those are the characters you actual need to "hide" to let the %LET work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let defineAnalysis1 = 
define _&amp;amp;fAcadYS._&amp;amp;fAcadYE. / analysis sum "_&amp;amp;fAcadYS.-&amp;amp;fAcadYE." %str(;)
define _%eval(&amp;amp;fAcadYS. +1)_%eval(&amp;amp;fAcadYE.+1) / analysis sum "_%eval(&amp;amp;fAcadYS. +1)_%eval(&amp;amp;fAcadYE.+1)" %str(;)
define _%eval(&amp;amp;fAcadYS. +2)_%eval(&amp;amp;fAcadYE.+2) / analysis sum "_%eval(&amp;amp;fAcadYS. +2)_%eval(&amp;amp;fAcadYE.+2)" %str(;)
define _%eval(&amp;amp;fAcadYS. +3)_%eval(&amp;amp;fAcadYE.+3) / analysis sum "_%eval(&amp;amp;fAcadYS. +3)_%eval(&amp;amp;fAcadYE.+3)" %str(;)
define _%eval(&amp;amp;fAcadYS. +4)_%eval(&amp;amp;fAcadYE.+4) / analysis sum "_%eval(&amp;amp;fAcadYS. +4)_%eval(&amp;amp;fAcadYE.+4)" %str(;)
;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Mar 2022 20:50:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Eval-with-Str/m-p/801738#M315544</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-11T20:50:14Z</dc:date>
    </item>
    <item>
      <title>Re: %Eval with %Str</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Eval-with-Str/m-p/801739#M315545</link>
      <description>&lt;P&gt;I'm sure all this could have been done using custom formats and PROC REPORT, rather than variables with calendar information in the variable name and macro variables and arithmetic with the macro variables. I don't have time right now to write out the code, but I think macro variables are completely unnecessary here, and makes the whole thing unnecessarily complicated..&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2022 20:56:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Eval-with-Str/m-p/801739#M315545</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-11T20:56:06Z</dc:date>
    </item>
    <item>
      <title>Re: %Eval with %Str</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Eval-with-Str/m-p/801743#M315548</link>
      <description>&lt;P&gt;Placing the %str only on the; worked.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2022 21:11:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Eval-with-Str/m-p/801743#M315548</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2022-03-11T21:11:13Z</dc:date>
    </item>
    <item>
      <title>Re: %Eval with %Str</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Eval-with-Str/m-p/801746#M315550</link>
      <description>&lt;P&gt;Since there is a lot of DEFINE code going on, one has to assume this is Proc Report code.&lt;/P&gt;
&lt;P&gt;Here may be a reason why all the code spent in generating variable names with data in them like _2018_19 was quite possibly unneeded and can get similar output.&lt;/P&gt;
&lt;P&gt;The data set cntlyr makes a format for a limited number of school years, start with a lower value, like 1900 and go as large as you want up to 9998. When we get past 4 digit years something else would be needed.&lt;/P&gt;
&lt;P&gt;Cntlyr is used to create a custom format to display single values of year such as 2018 as 2018-19.&lt;/P&gt;
&lt;P&gt;Then make small data set with random years and a variable to sum (or other summary) and some proc report code to make the Years as column headings with the summarized value under.&lt;/P&gt;
&lt;P&gt;This would expect to have variable in your basic data with an appropriate calendar year numeric variable. Simple change if your "year" is character to make the start value and format type character.&lt;/P&gt;
&lt;PRE&gt;data cntlyr;
fmtname='SchoolYr';
type='N';
do start=2000 to 2050;
   label= catx('-',start,put(mod(start,100) +1,z2.));
   output;
end;
run;

proc format cntlin=cntlyr;
run;

/* create a data set with random years and a variable to 
summarize
*/

data example;
   do i=1 to 100;
      year= 2000+ rand('integer',21);
      value= rand('integer',25);
      output;
   end;
run;

proc report data=example;
   column  year, value;
   define year/across format=schoolyr.;
   define value/analysis sum ' ';
run;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2022 21:30:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Eval-with-Str/m-p/801746#M315550</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-11T21:30:57Z</dc:date>
    </item>
    <item>
      <title>Re: %Eval with %Str</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Eval-with-Str/m-p/801799#M315585</link>
      <description>&lt;P&gt;Yes, I agree &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;, no macros needed here.&lt;/P&gt;</description>
      <pubDate>Sat, 12 Mar 2022 10:38:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Eval-with-Str/m-p/801799#M315585</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-12T10:38:56Z</dc:date>
    </item>
  </channel>
</rss>

