<?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: Dynamically adapting the value of a macro variable using call symputx in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Dynamically-adapting-the-value-of-a-macro-variable-using-call/m-p/522243#M4386</link>
    <description>&lt;P&gt;Even once you resolve that error, there is an additional reason the code will not work.&amp;nbsp; You cannot create &amp;amp;A within a DATA step, and then use it within the same DATA step.&amp;nbsp; Basically, SAS has to determine what your statements are all about, before it has created &amp;amp;A.&amp;nbsp; You would be better off keeping all your code in macro language:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let annee=2018;
%let mois=11;

%let a = %substr(&amp;amp;annee, 3, 2);
%let suiviassinc = dsi_asti.suiviassincnew&amp;amp;a&amp;amp;mois;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even if you must use a DATA step for some other reason, you can emulate the %LET statement with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
call symputx('suiviassinc', "dsi_asti.suiviassincnew&amp;amp;a&amp;amp;mois");
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 18 Dec 2018 15:30:26 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-12-18T15:30:26Z</dc:date>
    <item>
      <title>Dynamically adapting the value of a macro variable using call symputx</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Dynamically-adapting-the-value-of-a-macro-variable-using-call/m-p/522237#M4380</link>
      <description>&lt;P&gt;Hello I am struggling with the function substr() and symputx().&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;* I am trying to generate this variable automatically;
%let suiviassinc=dsi_asti.suiviassincnew1807;



*this is my code;


%let annee=2018; &lt;BR /&gt;%let mois=11; 

data _null_;  
	
	call symputx('a',substr("&amp;amp;annee",3,4));

        call symputx('suiviassinc',"dsi_asti.suiviassincnew&amp;amp;a&amp;amp;mois");
run;

&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Upon running the code I am getting the following error:&lt;/P&gt;&lt;P&gt;NOTE: Invalid third argument to function SUBSTR at line 397 column 22.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please explain the issue here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help&lt;/P&gt;</description>
      <pubDate>Tue, 18 Dec 2018 15:10:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Dynamically-adapting-the-value-of-a-macro-variable-using-call/m-p/522237#M4380</guid>
      <dc:creator>pkopersk</dc:creator>
      <dc:date>2018-12-18T15:10:56Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically adapting the value of a macro variable using call symputx</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Dynamically-adapting-the-value-of-a-macro-variable-using-call/m-p/522238#M4381</link>
      <description>&lt;P&gt;I have no clue what your real objective is i.e in other words what you want to accomplish and why the macro&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if you want &lt;STRONG&gt;just&lt;/STRONG&gt; &lt;STRONG&gt;help and only just&lt;/STRONG&gt; to make your code work, here you go&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
* I am trying to generate this variable automatically;
%let suiviassinc=dsi_asti.suiviassincnew1807;



*this is my code;


%let annee=2018; 
%let mois=11; 

data _null_;  
	
	call symputx('a',substr("&amp;amp;annee",3,2));

        call symputx('suiviassinc',resolve("dsi_asti.suiviassincnew&amp;amp;a&amp;amp;mois"));
run;

%put &amp;amp;suiviassinc;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Dec 2018 15:19:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Dynamically-adapting-the-value-of-a-macro-variable-using-call/m-p/522238#M4381</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-18T15:19:11Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically adapting the value of a macro variable using call symputx</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Dynamically-adapting-the-value-of-a-macro-variable-using-call/m-p/522239#M4382</link>
      <description>&lt;P&gt;SUBSTR third argument should be the length of text you want to extract, which in this case seems it should be 2 and not 4.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the future, please post the SASLOG when there are errors or warnings or notes that you don't understand.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Dec 2018 15:19:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Dynamically-adapting-the-value-of-a-macro-variable-using-call/m-p/522239#M4382</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-12-18T15:19:09Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically adapting the value of a macro variable using call symputx</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Dynamically-adapting-the-value-of-a-macro-variable-using-call/m-p/522240#M4383</link>
      <description>&lt;P&gt;The function substr() is of the form:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;substr(&amp;lt;string&amp;gt;,&amp;lt;start position&amp;gt;,&amp;lt;number of characters to read&amp;gt;)&lt;/PRE&gt;
&lt;P&gt;You are saying from the 3rd character, read 4 characters - which exceeds the length of the string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;call symputx('a',substr("&amp;amp;annee",3,4));
&lt;/PRE&gt;
&lt;P&gt;Should read:&lt;/P&gt;
&lt;PRE&gt;call symputx('a',substr("&amp;amp;annee",3,2));
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;To get the two characters from position 3 onwards, which is "18".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, you are overcomplicating your code, no need to create another macro variable, just do:&lt;/P&gt;
&lt;PRE&gt;%let suiviassinc=dsi_asti.suiviassincnew1807;
%let annee=2018; &lt;BR /&gt;%let mois=11; 

data _null_;  	
  call symputx('suiviassinc',cats("dsi_asti.suiviassincnew",substr("&amp;amp;annee.",3,4),"&amp;amp;mois."));
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Please also, always put the decimal point after macro variables.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Dec 2018 15:20:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Dynamically-adapting-the-value-of-a-macro-variable-using-call/m-p/522240#M4383</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-12-18T15:20:48Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically adapting the value of a macro variable using call symputx</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Dynamically-adapting-the-value-of-a-macro-variable-using-call/m-p/522243#M4386</link>
      <description>&lt;P&gt;Even once you resolve that error, there is an additional reason the code will not work.&amp;nbsp; You cannot create &amp;amp;A within a DATA step, and then use it within the same DATA step.&amp;nbsp; Basically, SAS has to determine what your statements are all about, before it has created &amp;amp;A.&amp;nbsp; You would be better off keeping all your code in macro language:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let annee=2018;
%let mois=11;

%let a = %substr(&amp;amp;annee, 3, 2);
%let suiviassinc = dsi_asti.suiviassincnew&amp;amp;a&amp;amp;mois;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even if you must use a DATA step for some other reason, you can emulate the %LET statement with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
call symputx('suiviassinc', "dsi_asti.suiviassincnew&amp;amp;a&amp;amp;mois");
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Dec 2018 15:30:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Dynamically-adapting-the-value-of-a-macro-variable-using-call/m-p/522243#M4386</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-12-18T15:30:26Z</dc:date>
    </item>
  </channel>
</rss>

