<?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: How to assign value to macro variable from another variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767654#M243406</link>
    <description>&lt;P&gt;Can't read your code, please reformat it.&lt;/P&gt;</description>
    <pubDate>Tue, 14 Sep 2021 10:41:29 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-09-14T10:41:29Z</dc:date>
    <item>
      <title>How to assign value to macro variable from another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767636#M243398</link>
      <description>&lt;P&gt;I'm doing a batch work with SAS programming, where I have a series of var to assign.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;with vars = va|vb|vc&lt;/P&gt;&lt;P&gt;, in a do loop&lt;/P&gt;&lt;P&gt;, get var = vars[i],&lt;/P&gt;&lt;P&gt;, get temp local var_i&lt;/P&gt;&lt;P&gt;, let &amp;amp;var(actually va/vb/vc) = &amp;amp;&amp;amp;var_&amp;amp;i;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But the last step isn't working, I guess SAS won't let variable resolved at [LET VAR_NM = ] syntax..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, Is there a function I may use to copy value from variable to variable?&lt;/P&gt;&lt;P&gt;Or any better way to finish this batch work?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks very much, Say hi to the community from Guangzhou, China.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 09:34:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767636#M243398</guid>
      <dc:creator>kimmygzc</dc:creator>
      <dc:date>2021-09-14T09:34:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign value to macro variable from another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767642#M243400</link>
      <description>&lt;P&gt;I'm not 100% sure I understand what you are asking here ... but maybe this is it ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro dothis;
%let vars=va vb vc;
%do i=1 %to %sysfunc(countw(&amp;amp;vars));
     %let var&amp;amp;i=%scan(&amp;amp;vars,&amp;amp;i,%str( ));
%end;
%put &amp;amp;var1 &amp;amp;var2 &amp;amp;var3;
%mend;
%dothis&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Sep 2021 10:04:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767642#M243400</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-14T10:04:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign value to macro variable from another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767646#M243401</link>
      <description>&lt;P&gt;Thanks for your reply, Sir. This is partial of my work though, once you get var1 which is the name of my wanted global vars, va respectively. I need to convey a local value from another temp var. I did [%let &amp;amp;&amp;amp;var&amp;amp;i = &amp;amp;var_temp] in your context, hoping this would make va = &amp;amp;var_temp globally, but It failed...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your patience again, Sir.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 10:22:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767646#M243401</guid>
      <dc:creator>kimmygzc</dc:creator>
      <dc:date>2021-09-14T10:22:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign value to macro variable from another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767647#M243402</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/397901"&gt;@kimmygzc&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for your reply, Sir. This is partial of my work though, once you get var1 which is the name of my wanted global vars, va respectively. I need to convey a local value from another temp var. I did [%let &amp;amp;&amp;amp;var&amp;amp;i = &amp;amp;var_temp] in your context, hoping this would make va = &amp;amp;var_temp globally, but It failed...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your patience again, Sir.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I guess then I don't understand what you are trying to do, and it would help if you can be more specific and give concrete examples of "I need to convey a local value from another temp var". I'm not asking for code, I'm asking what the macro variable values are how you want to move them around.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 10:25:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767647#M243402</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-14T10:25:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign value to macro variable from another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767650#M243405</link>
      <description>&lt;P&gt;Sure, Say:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let vars = va|vb|vc&lt;BR /&gt;&lt;BR /&gt;%macro&amp;nbsp;batch_assign;&lt;BR /&gt;%do i = 1 to %sysfunc(countw(&amp;amp;vars, %str(|)));&lt;BR /&gt;  var = %scan(&amp;amp;vars, &amp;amp;i, %str(|));&lt;BR /&gt;  %get_value(ind = i, tmep = t); /*In this func, t is assigned with 'Hi,1'/'Hi,2'/'Hi,3'*/&lt;BR /&gt;  %let &amp;amp;&amp;amp;var = &amp;amp;t; /*var should be twice resolved, which I think SAS would avoid.*/&lt;BR /&gt;%mend;&lt;BR /&gt;%batch_assign;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What&amp;nbsp;I&amp;nbsp;want&amp;nbsp;is,&amp;nbsp;globally,&amp;nbsp;I&amp;nbsp;have&amp;nbsp;va&amp;nbsp;= 'Hi,1',&amp;nbsp;vb&amp;nbsp;=&amp;nbsp;'Hi,2',&amp;nbsp;vc&amp;nbsp;=&amp;nbsp;'Hi,3'; Which&amp;nbsp;is&amp;nbsp;actually, batch&amp;nbsp;assignment&amp;nbsp;from&amp;nbsp;function&amp;nbsp;get_value.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 10:37:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767650#M243405</guid>
      <dc:creator>kimmygzc</dc:creator>
      <dc:date>2021-09-14T10:37:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign value to macro variable from another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767654#M243406</link>
      <description>&lt;P&gt;Can't read your code, please reformat it.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 10:41:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767654#M243406</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-14T10:41:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign value to macro variable from another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767657#M243407</link>
      <description>&lt;P&gt;Please show what you "have", and then what you "want" out of it.&lt;/P&gt;
&lt;P&gt;Syntactically erroneous one-line(!!!) code doesn't tell us anything.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 10:42:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767657#M243407</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-09-14T10:42:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign value to macro variable from another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767661#M243408</link>
      <description>&lt;P&gt;Sorry, Sir, Im new to this editor...&lt;/P&gt;&lt;PRE&gt;%let vars = va|vb|vc;
%macro batch_assign;
  %do i = 1 to %sysfunc(countw(&amp;amp;vars, %str(|)));  
  var = %scan(&amp;amp;vars, &amp;amp;i, %str(|));  
  %get_value(ind = i, tmep = t); /*In this func, t is assigned with 'Hi,1'/'Hi,2'/'Hi,3'*/  
  %let &amp;amp;var = &amp;amp;t; 
/*var should be resolved and refered to va/vb/vc
, which I think SAS would avoid.*/
%mend;
%batch_assign;
&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;In case if it's not formatted in the block:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let vars = va|vb|vc;&lt;/P&gt;&lt;P&gt;%macro batch_assign;&lt;BR /&gt;%do i = 1 to %sysfunc(countw(&amp;amp;vars, %str(|)));&lt;BR /&gt;&amp;nbsp; var = %scan(&amp;amp;vars, &amp;amp;i, %str(|));&lt;BR /&gt;&amp;nbsp; %get_value(ind = i, tmep = t); /*In this func, t is assigned with 'Hi,1'/'Hi,2'/'Hi,3'*/&lt;BR /&gt;&amp;nbsp; %let &amp;amp;var = &amp;amp;t;&lt;BR /&gt;&amp;nbsp; /*var should be resolved and refered to va/vb/vc&lt;BR /&gt;&amp;nbsp; , which I think SAS would avoid.*/&lt;BR /&gt;%mend;&lt;BR /&gt;%batch_assign;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 10:47:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767661#M243408</guid>
      <dc:creator>kimmygzc</dc:creator>
      <dc:date>2021-09-14T10:47:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign value to macro variable from another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767664#M243410</link>
      <description>&lt;P&gt;Your code has a wrong %DO statement (no &lt;FONT color="#FF0000"&gt;%&lt;/FONT&gt;TO) and misses a %END to close the %DO.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 10:52:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767664#M243410</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-09-14T10:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign value to macro variable from another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767666#M243411</link>
      <description>&lt;P&gt;Earlier, I asked for a concrete example showing how values are assigned to the different macro variables. I specifically said I do not want to see code. I don't know what %get_value does, so this isn't helping.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I can see is this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;amp;i=1&lt;/P&gt;
&lt;P&gt;then &amp;amp;var is assigned the value va.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What happens next (without writing code, what is the next thing that happens)? Then keep going through the entire example.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 10:55:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767666#M243411</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-14T10:55:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign value to macro variable from another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767668#M243412</link>
      <description>&lt;P&gt;Yeah, When &amp;amp;i = 1, var = va, I get t = 'Hi, 1' in the %get_value function.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I do this in do macro %batch_assign;&lt;/P&gt;&lt;PRE&gt;%let &amp;amp;var = &amp;amp;t;&lt;/PRE&gt;&lt;P&gt;I want globally va = 'Hi, 1'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My SAS is on the company cloud environment, can't just copy code from there. I'm pretty sorry to make it looks complex here. Thanks, Sir.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 11:00:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767668#M243412</guid>
      <dc:creator>kimmygzc</dc:creator>
      <dc:date>2021-09-14T11:00:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign value to macro variable from another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767669#M243413</link>
      <description>&lt;P&gt;First, you almost never want macro variable values to be enclosed in quotes. That's just not necessary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next, you say "I get t = 'Hi, 1' in the %get_value function." Does this mean that macro variable &amp;amp;t is assigned the value of 'Hi, 1'? Because the way you wrote it when you referred to t, it seems like it is not a macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since I still don't know what %get_value does, perhaps adding in&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%global t;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;right at the top of the code will allow &amp;amp;t to pass its value into your command&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let &amp;amp;var=&amp;amp;t;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 11:18:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767669#M243413</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-14T11:18:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign value to macro variable from another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767670#M243414</link>
      <description>&lt;P&gt;Is this what you want?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let vars = va|vb|vc;

%macro assign;
%do i = 1 %to %sysfunc(countw(&amp;amp;vars.,|));
  %global %scan(&amp;amp;vars,&amp;amp;i,|);
  %let %scan(&amp;amp;vars,&amp;amp;i,|) = Hi, &amp;amp;i.;
%end;
%mend;
%assign

%put &amp;amp;=va &amp;amp;=vb &amp;amp;=vc;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Sep 2021 11:16:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767670#M243414</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-09-14T11:16:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign value to macro variable from another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767671#M243415</link>
      <description>&lt;P&gt;Thanks,Sir. Guess I know what's going on here.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since I %let &amp;amp;var = &amp;amp;t; in the Macro %batch_assign, I&amp;nbsp;was thinking SAS won't allow %let resolve a variable, All I need is just state &amp;amp;var global before I pass in values(coz generally if you use %let globally, it's OK not to make a statement, it doesn't hit me until you say so)...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's solved now, Thank you very much!&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 11:21:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767671#M243415</guid>
      <dc:creator>kimmygzc</dc:creator>
      <dc:date>2021-09-14T11:21:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign value to macro variable from another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767672#M243416</link>
      <description>&lt;P&gt;Oh, yes! This avoid a transit assignment, Thank you, Sir!&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 11:26:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767672#M243416</guid>
      <dc:creator>kimmygzc</dc:creator>
      <dc:date>2021-09-14T11:26:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign value to macro variable from another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767673#M243417</link>
      <description>&lt;P&gt;Alternatively, you can do it in a DATA step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
vars = "&amp;amp;vars";
do i = 1 to countw(vars,"|");
  call symputx(scan(vars,i,"|"),catx(" ","Hi,",i),"g");
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Sep 2021 11:35:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-value-to-macro-variable-from-another-variable/m-p/767673#M243417</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-09-14T11:35:11Z</dc:date>
    </item>
  </channel>
</rss>

