<?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 Dynamic Macro Variable Creation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Variable-Creation/m-p/339954#M77622</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create some macro variable with the help of another macro variable. Please suggest how i can resolve below code?&lt;/P&gt;&lt;P&gt;I am in some sort of programming where i can just edit this macro only. So kindly dont suggest to create another macro. I can only edit this one.&lt;/P&gt;&lt;PRE&gt;%macro rowToMacroVariable(dataSetName,variableName,macroVariableName);
data _null_;
set &amp;amp;dataSetName;
call symputx("&amp;amp;macroVariableName"||strip(put(_n_,best.)),&amp;amp;variableName,"G");
run;
%mend;
data ab;
input brand$ impress$;
cards;
b TJ
c DJ
d PJ
;
run;
%rowToMacroVariable(ab,brand,brand);
%rowToMacroVariable(ab,impress,var_&amp;amp;brand);
%put _GLOBAL_;



&lt;/PRE&gt;&lt;P&gt;Now with the help of above code i want to create&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;brand1=b brand2=c brand3=d which is working perfectly fine. But in next row when i am trying to create &lt;STRONG&gt;&lt;FONT color="#000000"&gt;var_b=TJ var_c=DJ var_d=PJ &lt;/FONT&gt;&lt;/STRONG&gt;it throws an error. I am not sure why this is hapenning?&lt;/P&gt;</description>
    <pubDate>Fri, 10 Mar 2017 10:17:11 GMT</pubDate>
    <dc:creator>tjain90</dc:creator>
    <dc:date>2017-03-10T10:17:11Z</dc:date>
    <item>
      <title>Dynamic Macro Variable Creation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Variable-Creation/m-p/339954#M77622</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create some macro variable with the help of another macro variable. Please suggest how i can resolve below code?&lt;/P&gt;&lt;P&gt;I am in some sort of programming where i can just edit this macro only. So kindly dont suggest to create another macro. I can only edit this one.&lt;/P&gt;&lt;PRE&gt;%macro rowToMacroVariable(dataSetName,variableName,macroVariableName);
data _null_;
set &amp;amp;dataSetName;
call symputx("&amp;amp;macroVariableName"||strip(put(_n_,best.)),&amp;amp;variableName,"G");
run;
%mend;
data ab;
input brand$ impress$;
cards;
b TJ
c DJ
d PJ
;
run;
%rowToMacroVariable(ab,brand,brand);
%rowToMacroVariable(ab,impress,var_&amp;amp;brand);
%put _GLOBAL_;



&lt;/PRE&gt;&lt;P&gt;Now with the help of above code i want to create&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;brand1=b brand2=c brand3=d which is working perfectly fine. But in next row when i am trying to create &lt;STRONG&gt;&lt;FONT color="#000000"&gt;var_b=TJ var_c=DJ var_d=PJ &lt;/FONT&gt;&lt;/STRONG&gt;it throws an error. I am not sure why this is hapenning?&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2017 10:17:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Variable-Creation/m-p/339954#M77622</guid>
      <dc:creator>tjain90</dc:creator>
      <dc:date>2017-03-10T10:17:11Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macro Variable Creation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Variable-Creation/m-p/339959#M77624</link>
      <description>&lt;P&gt;This works:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro rowToMacroVariable(dataSetName,variableName,macroVariableName);
data _null_;
set &amp;amp;dataSetName;
call symputx("&amp;amp;macroVariableName"||strip(put(_n_,best.)),%trim(&amp;amp;variableName),"G");
run;
%mend;
data ab;
input brand$ impress$;
cards;
b TJ
c DJ
d PJ
;
run;
%rowToMacroVariable(ab,brand,brand);

%put _GLOBAL_;
&lt;/PRE&gt;
&lt;P&gt;And creates the three macro variables. &amp;nbsp;This line however:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%rowToMacroVariable(ab,impress,var_&amp;amp;brand);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There is no macro variable in the code you have provided for var_&amp;amp;brand. &amp;nbsp;It does not exist hence the error. &amp;nbsp;Perhaps you meant;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%rowToMacroVariable(ab,impress,var_&amp;amp;brand1.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would again take this opportunity to state that this code is not the way to proceed. &amp;nbsp;You are far overcomplicating your problems and leading to much more serious problems down the line.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2017 10:54:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Variable-Creation/m-p/339959#M77624</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-03-10T10:54:19Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macro Variable Creation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Variable-Creation/m-p/339960#M77625</link>
      <description>&lt;P&gt;Actually when you are&amp;nbsp;calling the macro&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%rowToMacroVariable(ab,impress,var_&amp;amp;brand);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yor are givng &amp;amp;brand when calling the macro .there is no macro variable present with the name Brand&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;there are macro variable present but they have different names brand1,brand2 and brand =3 which are created when you have run below line&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%rowToMacroVariable(ab,brand,brand);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;that why you will be getting error in the log because no macro varibale is present with name- brand&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2017 11:06:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Variable-Creation/m-p/339960#M77625</guid>
      <dc:creator>Rohit12</dc:creator>
      <dc:date>2017-03-10T11:06:31Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macro Variable Creation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Variable-Creation/m-p/339961#M77626</link>
      <description>&lt;P&gt;Thanks RW9.&lt;/P&gt;&lt;P&gt;Actully issue is with&lt;/P&gt;&lt;LI-SPOILER&gt;&lt;SPAN class="token macroname"&gt;%rowToMacroVariable&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;ab&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;impress&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;var_&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;brand&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/LI-SPOILER&gt;&lt;P&gt;Because Here i cannot use &amp;amp;brand1 or 2 because its not in loop. I dont want to run loop because my func will again open whole dataset and create various unwanted variables. So I will explain once more my problem statment is :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 100's of rows in data set. But some how programing is already done with the help of this 100's of macro variable. So currenty we are using like&lt;/P&gt;&lt;P&gt;%let brand1=b&lt;/P&gt;&lt;P&gt;%let brand2=c and so on.&lt;/P&gt;&lt;P&gt;So my motive was to remove this code and for this i have created a dataset. Now Call Symputx works very well fine if i am using static variable name that is "brand". But now i want to combine this "brand1" with some other text to create another variable.&lt;/P&gt;&lt;P&gt;i want to pass &lt;STRONG&gt;var_&amp;amp;brand&lt;/STRONG&gt; and i want it will create var_b. I donnot want to make it in loop. So is there any way ? or can you suggest what is the best way for this problem statment ?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2017 11:09:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Variable-Creation/m-p/339961#M77626</guid>
      <dc:creator>tjain90</dc:creator>
      <dc:date>2017-03-10T11:09:37Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macro Variable Creation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Variable-Creation/m-p/339962#M77627</link>
      <description>&lt;P&gt;Hi Rohit,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Agreed this is because &amp;amp;brand is not resolved, but i want to know how i can relove it in Call symput because it is creating below error. Can you have some look in snapshot attached.&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/13544i52B51D4E2FC004DF/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;</description>
      <pubDate>Fri, 10 Mar 2017 11:13:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Variable-Creation/m-p/339962#M77627</guid>
      <dc:creator>tjain90</dc:creator>
      <dc:date>2017-03-10T11:13:18Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macro Variable Creation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Variable-Creation/m-p/339963#M77628</link>
      <description>&lt;P&gt;So your going to create hundreds of macro variables and then hundreds more with a slightly different name, to run several macros.&lt;/P&gt;
&lt;P&gt;I am sorry, you are lost to madness. &amp;nbsp;Base SAS is a programming language deisnged to process datasets there are lots of functions, data modelling techniques, and processes deisgned for making data processing simple and easily maintainable. &amp;nbsp;You are ignoring this in total and remaking the whole thing in macro language, hence I can't help any further.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2017 11:16:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Variable-Creation/m-p/339963#M77628</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-03-10T11:16:13Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macro Variable Creation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Variable-Creation/m-p/339965#M77629</link>
      <description>The reason I am dong this because I am not authorized to touch those already programmed algorithms. I am trying to optimize it in best possible way. But it seems like you are very much resistive with the procedure and technique you follow. So no worry but still thanks for your suggestions &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Fri, 10 Mar 2017 11:21:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Variable-Creation/m-p/339965#M77629</guid>
      <dc:creator>tjain90</dc:creator>
      <dc:date>2017-03-10T11:21:37Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macro Variable Creation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Variable-Creation/m-p/339971#M77630</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your goal is only to generate var_&amp;lt;brand&amp;gt; macrovariables, you can do it directly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data _NULL_;
    set ab;
    call symput(cats("var_",brand),impress);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Mar 2017 11:54:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macro-Variable-Creation/m-p/339971#M77630</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2017-03-10T11:54:36Z</dc:date>
    </item>
  </channel>
</rss>

