<?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: Adding quotes on both sides of a macro variable and removing leading spaces. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Adding-quotes-on-both-sides-of-a-macro-and-removing-leading/m-p/916826#M361129</link>
    <description>&lt;P&gt;That is easy to see what is happening:&lt;/P&gt;
&lt;P&gt;Look at these two lines:&lt;/P&gt;
&lt;PRE&gt;32         	%let academicPeriods = "%eval(&amp;amp;fAcadP. +&amp;amp;i*100)";
33         	%do i=2 %to &amp;amp;n - 1;&lt;/PRE&gt;
&lt;P&gt;In line 32 you reference &amp;amp;I, but you don't give I a value until line 33.&lt;/P&gt;</description>
    <pubDate>Mon, 19 Feb 2024 17:05:14 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-02-19T17:05:14Z</dc:date>
    <item>
      <title>Adding quotes on both sides of a macro and removing leading spaces.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-quotes-on-both-sides-of-a-macro-and-removing-leading/m-p/916796#M361117</link>
      <description>&lt;P&gt;I have a set of macro variables that I generated statically that I need to generate dynamically with a number of years parameter.&amp;nbsp; The macro variable needs to have quotes on both sides and no leading spaces.&amp;nbsp; An easy way to do this might be without making a macro loop.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The text that I want is:&lt;/P&gt;
&lt;P&gt;("201110", "201210", "201310")&lt;/P&gt;
&lt;P&gt;when the parameter is 3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;("201110", "201210")&lt;/P&gt;
&lt;P&gt;when the parameter is 2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The closest I have so far is the script below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%global academicPeriods;

%let fAcadP=201010;
%let fAcadYS=2009;

%let academicPeriods = %str();

%macro Parameters(n);
	%let academicPeriods = %str();
	%do i=1 %to &amp;amp;n - 1;
		%put &amp;amp;academicPeriods;
			%let academicPeriods = %sysfunc(cat(&amp;amp;academicPeriods, %eval(&amp;amp;fAcadP. +&amp;amp;i*100)", "));
	%end;
	%let academicPeriods =&amp;amp;academicPeriods %eval(&amp;amp;fAcadP +&amp;amp;n*100); 
%mend;
%Parameters(3);
%put(&amp;amp;academicPeriods);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Feb 2024 14:51:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-quotes-on-both-sides-of-a-macro-and-removing-leading/m-p/916796#M361117</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2024-02-19T14:51:35Z</dc:date>
    </item>
    <item>
      <title>Re: Adding quotes on both sides of a macro and removing leading spaces.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-quotes-on-both-sides-of-a-macro-and-removing-leading/m-p/916814#M361120</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro academicperiods(number);
data _null_;
length result $32767;
year = 2010;
do year = 1 to &amp;amp;number.;
  result = catx(",",result,quote(put(year,4.)!!"10"));
end;
result = cats("(",result,")"));
calo symputx("academicperiods",result,"g");
run;
%mend;
%academicperiods(2)
  &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Feb 2024 16:09:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-quotes-on-both-sides-of-a-macro-and-removing-leading/m-p/916814#M361120</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-02-19T16:09:25Z</dc:date>
    </item>
    <item>
      <title>Re: Adding quotes on both sides of a macro and removing leading spaces.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-quotes-on-both-sides-of-a-macro-and-removing-leading/m-p/916816#M361121</link>
      <description>&lt;P&gt;How about this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro Parameters(n);
	%let academicPeriods = "%eval(&amp;amp;fAcadP. +&amp;amp;i*100)";
	%do i=2 %to &amp;amp;n - 1;
		%let academicPeriods = &amp;amp;academicPeriods ,"%eval(&amp;amp;fAcadP. +&amp;amp;i*100)";
	%end;
	%let academicPeriods =&amp;amp;academicPeriods, "%eval(&amp;amp;fAcadP +&amp;amp;n*100)"; 
%mend;
%Parameters(3);
%put NOTE: %superq(academicPeriods);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Feb 2024 16:15:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-quotes-on-both-sides-of-a-macro-and-removing-leading/m-p/916816#M361121</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2024-02-19T16:15:10Z</dc:date>
    </item>
    <item>
      <title>Re: Adding quotes on both sides of a macro and removing leading spaces.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-quotes-on-both-sides-of-a-macro-and-removing-leading/m-p/916818#M361123</link>
      <description>&lt;P&gt;Mark, thanks for replying to my thread.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I should have included the above let statements above:&lt;/P&gt;
&lt;P&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: &lt;BR /&gt;201010 +&amp;amp;i*100 &lt;BR /&gt;ERROR: The macro PARAMETERS will stop executing.&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%global academicPeriods fAcadP;

%let fAcadP=201010;

%macro Parameters(n);
	%let academicPeriods = "%eval(&amp;amp;fAcadP. +&amp;amp;i*100)";
	%do i=2 %to &amp;amp;n - 1;
		%let academicPeriods = &amp;amp;academicPeriods ,"%eval(&amp;amp;fAcadP. +&amp;amp;i*100)";
	%end;
	%let academicPeriods =&amp;amp;academicPeriods, "%eval(&amp;amp;fAcadP +&amp;amp;n*100)"; 
%mend;
%Parameters(3);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2024 16:36:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-quotes-on-both-sides-of-a-macro-and-removing-leading/m-p/916818#M361123</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2024-02-19T16:36:29Z</dc:date>
    </item>
    <item>
      <title>Re: Adding quotes on both sides of a macro variable and removing leading spaces.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-quotes-on-both-sides-of-a-macro-and-removing-leading/m-p/916820#M361124</link>
      <description>&lt;P&gt;It is almost never helpful to show us the error messages detached from the code. It is always helpful to show us the entire log for the run of your macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you are dealing with a macro, please turn on the macro debugging option by running this command.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then run your macro and show us the log. Please show us the log by copying it as text and pasting it into the window that appears when you click on the &amp;lt;/&amp;gt; icon.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PaigeMiller_0-1699900743276.png" style="width: 859px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/89703i797B759183DE7484/image-size/large?v=v2&amp;amp;px=999" role="button" title="PaigeMiller_0-1699900743276.png" alt="PaigeMiller_0-1699900743276.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2024 16:50:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-quotes-on-both-sides-of-a-macro-and-removing-leading/m-p/916820#M361124</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-02-19T16:50:36Z</dc:date>
    </item>
    <item>
      <title>Re: Adding quotes on both sides of a macro and removing leading spaces.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-quotes-on-both-sides-of-a-macro-and-removing-leading/m-p/916822#M361126</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5059"&gt;@DavidPhillips2&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is my implementation&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro Parameters(p_inStart=, p_count=, p_rtrnMacVarName=);
	%local 
		l_inStart
		l_i 
		l_dt;

	/* Generate space delimited Annual intervals */
	%let l_inStart = %sysfunc(inputn(&amp;amp;p_inStart,yymmn6.));
	%do l_i=1 %to &amp;amp;p_count;
		%let l_dt = %sysfunc(intnx(year,&amp;amp;l_inStart,&amp;amp;l_i,same));
		%let &amp;amp;p_rtrnMacVarName = &amp;amp;&amp;amp;&amp;amp;p_rtrnMacVarName %sysfunc(putn(&amp;amp;l_dt,yymmn6.));
	%end;
	
	/* Add sorounding double quotes ("") and delimit by comma (,) */
	%let &amp;amp;p_rtrnMacVarName =%str(%")%qsysfunc(tranwrd(&amp;amp;&amp;amp;&amp;amp;p_rtrnMacVarName,%str( ),%str(%",%") ))%str(%");
%mend;

%global academicPeriods;
%let academicPeriods = ;
%Parameters(p_inStart=201010, p_count=3, p_rtrnMacVarName=academicPeriods);
%put &amp;amp;=academicPeriods;
%put (&amp;amp;academicPeriods);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put &amp;amp;=academicPeriods;
ACADEMICPERIODS="201110","201210","201310"
%put (&amp;amp;academicPeriods);
("201110","201210","201310")&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This code avoids using global macro variable, only parameters passed into it. The starting date is a YYYYMM parameter, the interval count is a parameter, and a single line to quote the intervals and delimit by comma.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;Ahmed&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2024 16:55:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-quotes-on-both-sides-of-a-macro-and-removing-leading/m-p/916822#M361126</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2024-02-19T16:55:27Z</dc:date>
    </item>
    <item>
      <title>Re: Adding quotes on both sides of a macro variable and removing leading spaces.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-quotes-on-both-sides-of-a-macro-and-removing-leading/m-p/916823#M361127</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;1                                                          The SAS System                            11:56 Monday, February 19, 2024

1          ;*';*";*/;quit;run;
2          OPTIONS PAGENO=MIN;
3          %LET _CLIENTTASKLABEL='Program';
4          %LET _CLIENTPROCESSFLOWNAME='Process Flow';
5          %LET _CLIENTPROJECTPATH='';
6          %LET _CLIENTPROJECTPATHHOST='';
7          %LET _CLIENTPROJECTNAME='';
8          %LET _SASPROGRAMFILE='';
9          %LET _SASPROGRAMFILEHOST='';
10         
11         ODS _ALL_ CLOSE;
12         OPTIONS DEV=PNG;
13         GOPTIONS XPIXELS=0 YPIXELS=0;
14         FILENAME EGSR TEMP;
15         ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR
16             STYLE=HtmlBlue
17             STYLESHEET=(URL="file:///C:/Program%20Files/SAS7Home/SASEnterpriseGuide/7.1/Styles/HtmlBlue.css")
18             NOGTITLE
19             NOGFOOTNOTE
20             GPATH=&amp;amp;sasworklocation
21             ENCODING=UTF8
22             options(rolap="on")
23         ;
NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
24         
25         GOPTIONS ACCESSIBLE;
26         options mprint;
27         %global academicPeriods fAcadP;
28         
29         %let fAcadP=201010;
30         
31         %macro Parameters(n);
32         	%let academicPeriods = "%eval(&amp;amp;fAcadP. +&amp;amp;i*100)";
33         	%do i=2 %to &amp;amp;n - 1;
34         		%let academicPeriods = &amp;amp;academicPeriods ,"%eval(&amp;amp;fAcadP. +&amp;amp;i*100)";
35         	%end;
36         	%let academicPeriods =&amp;amp;academicPeriods, "%eval(&amp;amp;fAcadP +&amp;amp;n*100)";
37         %mend;
38         %Parameters(3);
WARNING: Apparent symbolic reference I not resolved.
WARNING: Apparent symbolic reference I not resolved.
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: 
       201010 +&amp;amp;i*100 
ERROR: The macro PARAMETERS will stop executing.
39         
40         GOPTIONS NOACCESSIBLE;
41         %LET _CLIENTTASKLABEL=;
42         %LET _CLIENTPROCESSFLOWNAME=;
43         %LET _CLIENTPROJECTPATH=;
44         %LET _CLIENTPROJECTPATHHOST=;
45         %LET _CLIENTPROJECTNAME=;
46         %LET _SASPROGRAMFILE=;
47         %LET _SASPROGRAMFILEHOST=;
48         
49         ;*';*";*/;quit;run;
50         ODS _ALL_ CLOSE;
51         
52         
2                                                          The SAS System                            11:56 Monday, February 19, 2024

53         QUIT; RUN;
54         
&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint; %global academicPeriods fAcadP; %let fAcadP=201010; %macro Parameters(n); %let academicPeriods = "%eval(&amp;amp;fAcadP. +&amp;amp;i*100)"; %do i=2 %to &amp;amp;n - 1; %let academicPeriods = &amp;amp;academicPeriods ,"%eval(&amp;amp;fAcadP. +&amp;amp;i*100)"; %end; %let academicPeriods =&amp;amp;academicPeriods, "%eval(&amp;amp;fAcadP +&amp;amp;n*100)"; %mend; %Parameters(3);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2024 16:58:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-quotes-on-both-sides-of-a-macro-and-removing-leading/m-p/916823#M361127</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2024-02-19T16:58:29Z</dc:date>
    </item>
    <item>
      <title>Re: Adding quotes on both sides of a macro variable and removing leading spaces.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-quotes-on-both-sides-of-a-macro-and-removing-leading/m-p/916824#M361128</link>
      <description>&lt;PRE&gt;31         %macro Parameters(n);
32         	%let academicPeriods = "%eval(&amp;amp;fAcadP. +&amp;amp;i*100)";&lt;/PRE&gt;
&lt;P&gt;&amp;amp;i does not have a value&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2024 17:02:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-quotes-on-both-sides-of-a-macro-and-removing-leading/m-p/916824#M361128</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-02-19T17:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: Adding quotes on both sides of a macro variable and removing leading spaces.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-quotes-on-both-sides-of-a-macro-and-removing-leading/m-p/916826#M361129</link>
      <description>&lt;P&gt;That is easy to see what is happening:&lt;/P&gt;
&lt;P&gt;Look at these two lines:&lt;/P&gt;
&lt;PRE&gt;32         	%let academicPeriods = "%eval(&amp;amp;fAcadP. +&amp;amp;i*100)";
33         	%do i=2 %to &amp;amp;n - 1;&lt;/PRE&gt;
&lt;P&gt;In line 32 you reference &amp;amp;I, but you don't give I a value until line 33.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2024 17:05:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-quotes-on-both-sides-of-a-macro-and-removing-leading/m-p/916826#M361129</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-19T17:05:14Z</dc:date>
    </item>
    <item>
      <title>Re: Adding quotes on both sides of a macro and removing leading spaces.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-quotes-on-both-sides-of-a-macro-and-removing-leading/m-p/916827#M361130</link>
      <description>&lt;P&gt;I should be able to convert the code block you posted to what I need.&amp;nbsp; It looks like i needed to use&amp;nbsp;%str(%") and tranward.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2024 17:05:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-quotes-on-both-sides-of-a-macro-and-removing-leading/m-p/916827#M361130</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2024-02-19T17:05:44Z</dc:date>
    </item>
    <item>
      <title>Re: Adding quotes on both sides of a macro and removing leading spaces.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-quotes-on-both-sides-of-a-macro-and-removing-leading/m-p/916829#M361131</link>
      <description>&lt;P&gt;Why are you trying to use the SAS function CAT() in macro code?&amp;nbsp; There is not utility in doing that.&amp;nbsp; To concatenate values in macro code just place them next to each other.&amp;nbsp; Plus the CAT() series of functsion does not play well with %SYSFUNC() because they can take either character values or numeric values so poor %SYSFUNC() has to guess which type it should tell the CAT() function your macro expressions (which are always strings) are.&lt;/P&gt;
&lt;P&gt;Start your %DO loop from ZERO instead of 1.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let fAcadP=201010;
%macro Parameters(n);
  %local i sep;
(%do i=0 %to &amp;amp;n - 1;&amp;amp;sep."%eval(&amp;amp;facadp+100&amp;amp;i)"%let sep=,;%end;)
%mend;
%let academicPeriods = %Parameters(3);
%put &amp;amp;=academicperiods;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or do the task in actual SAS code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let fAcadP=201010;
%let n=3;
data _null_;
  length result $3000;
  do i=0 to &amp;amp;n-1;
    result=catx(',',result,quote(put(&amp;amp;fAcadP+100*i,6.)));
  end;
  call symputx('academicperiods',cats('(',result,')'),'g');
run;
%put &amp;amp;=academicperiods;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Feb 2024 17:22:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-quotes-on-both-sides-of-a-macro-and-removing-leading/m-p/916829#M361131</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-19T17:22:23Z</dc:date>
    </item>
    <item>
      <title>Re: Adding quotes on both sides of a macro and removing leading spaces.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-quotes-on-both-sides-of-a-macro-and-removing-leading/m-p/916837#M361132</link>
      <description>&lt;P&gt;Thanks for posting the data step code.&amp;nbsp; That is much cleaner.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2024 18:27:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-quotes-on-both-sides-of-a-macro-and-removing-leading/m-p/916837#M361132</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2024-02-19T18:27:24Z</dc:date>
    </item>
  </channel>
</rss>

