<?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 pass a macro variable through tranwrd function for each data row? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-a-macro-variable-through-tranwrd-function-for-each/m-p/432947#M107278</link>
    <description>&lt;P&gt;Why are you using a macro variable at all?&lt;/P&gt;
&lt;P&gt;Since you want to use the current value of Firstname to replace text on that record there is not reason to create a macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you try some&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;question2&amp;nbsp;= tranwrd(question,"{{lead.First Name}}", strip(FirstName) );&lt;/P&gt;</description>
    <pubDate>Wed, 31 Jan 2018 23:57:11 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-01-31T23:57:11Z</dc:date>
    <item>
      <title>How to pass a macro variable through tranwrd function for each data row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-a-macro-variable-through-tranwrd-function-for-each/m-p/432939#M107274</link>
      <description>&lt;P&gt;Hi there&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As a simple example , I have a data set that looks like below - the question the person gets asked depends on other criteria, and at the end I want to populate the person's name into question2 instead of the dummy tag.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried using tranwrd and this works for part of my problem - but it&amp;nbsp;replaces {{lead.FirstName}}&amp;nbsp;&amp;nbsp;in Question2 to say "Tom" for every row as this is the last name in my data set.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the code I am using is (in Base SAS 9.4):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;set test;&lt;BR /&gt;call symput('FirstName2',trim(FirstName));&lt;BR /&gt;question2&amp;nbsp;= (tranwrd(question,"{{lead.First Name}}","&amp;amp;FirstName2.");&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please could someone help me on how I get the correct name populated in each data row? have been searching and trying things for&amp;nbsp;hours but can't find anything.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;FirstName&lt;/TD&gt;&lt;TD&gt;Question&lt;/TD&gt;&lt;TD&gt;Question2 (what I want it to say)&lt;/TD&gt;&lt;TD&gt;Question2 (what it actually does)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Caroline&lt;/TD&gt;&lt;TD&gt;{{lead.First Name}}, do you have a red car?&lt;/TD&gt;&lt;TD&gt;Caroline, do you have a red car?&lt;/TD&gt;&lt;TD&gt;Tom, do you have a red car?&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Mike&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;{{lead.First Name}}, do you have a blue car?&lt;/TD&gt;&lt;TD&gt;Mike, do you have a blue car?&lt;/TD&gt;&lt;TD&gt;Tom, do you have a blue car?&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Eden&lt;/TD&gt;&lt;TD&gt;{{lead.First Name}}, do you have a green car?&lt;/TD&gt;&lt;TD&gt;Eden, do you have a green car?&lt;/TD&gt;&lt;TD&gt;Tom, do you have a green car?&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Tom&lt;/TD&gt;&lt;TD&gt;{{lead.First Name}}, do you have a black car?&lt;/TD&gt;&lt;TD&gt;Tom, do you have a black car?&lt;/TD&gt;&lt;TD&gt;Tom, do you have a black car?&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 31 Jan 2018 23:16:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-a-macro-variable-through-tranwrd-function-for-each/m-p/432939#M107274</guid>
      <dc:creator>ScoobieR</dc:creator>
      <dc:date>2018-01-31T23:16:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass a macro variable through tranwrd function for each data row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-a-macro-variable-through-tranwrd-function-for-each/m-p/432947#M107278</link>
      <description>&lt;P&gt;Why are you using a macro variable at all?&lt;/P&gt;
&lt;P&gt;Since you want to use the current value of Firstname to replace text on that record there is not reason to create a macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you try some&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;question2&amp;nbsp;= tranwrd(question,"{{lead.First Name}}", strip(FirstName) );&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 23:57:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-a-macro-variable-through-tranwrd-function-for-each/m-p/432947#M107278</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-01-31T23:57:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass a macro variable through tranwrd function for each data row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-a-macro-variable-through-tranwrd-function-for-each/m-p/432950#M107279</link>
      <description>&lt;P&gt;SAS resolves the macro code/references before it compiles and runs the data step.&lt;/P&gt;
&lt;P&gt;So the first time you ran it it would have generated this value instead.&lt;/P&gt;
&lt;PRE&gt;&amp;amp;Firstname2., do you have a red car?&lt;/PRE&gt;
&lt;P&gt;And written this note into the log:&lt;/P&gt;
&lt;PRE&gt;WARNING: Apparent symbolic reference FIRSTNAME2 not resolved.
&lt;/PRE&gt;
&lt;P&gt;It is only after you had run the step at least once that FIRSTNAME2 had a value and of course it just has the value from the last observation as at each iteration of the data step the macro variable's value is getting changed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do not use a macro variable for this problem as there is nothing about it that requires you to generate any code.&lt;/P&gt;
&lt;P&gt;Just use the value that is already in the dataset!!&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;question2 = tranwrd(question,'{{lead.First Name}}',trim(FirstName)) ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Feb 2018 00:20:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-a-macro-variable-through-tranwrd-function-for-each/m-p/432950#M107279</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-02-01T00:20:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass a macro variable through tranwrd function for each data row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-a-macro-variable-through-tranwrd-function-for-each/m-p/432952#M107280</link>
      <description>&lt;P&gt;Thank you Tom and BallardW - I don't know why I didn't try this - I thought the last parameter of tranwrd had to be in quotes! Clearly been looking at it too long.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Both great and helpful replies - thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 00:36:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-a-macro-variable-through-tranwrd-function-for-each/m-p/432952#M107280</guid>
      <dc:creator>ScoobieR</dc:creator>
      <dc:date>2018-02-01T00:36:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass a macro variable through tranwrd function for each data row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-a-macro-variable-through-tranwrd-function-for-each/m-p/432956#M107284</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31965"&gt;@ScoobieR&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thank you Tom and BallardW - I don't know why I didn't try this - I thought the last parameter of tranwrd had to be in quotes! Clearly been looking at it too long.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Both great and helpful replies - thank you.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The quotes would be needed if I want to set a specific value, not a variable,&amp;nbsp;for all records. Such as&lt;/P&gt;
&lt;P&gt;tranwrd (schoolname, 'HS', 'High School');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The requirement is that the result be a character value. You can even do operations such as concatenating a string and a variable, or multiple variables, or the substr of a variable or ...&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 00:58:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-a-macro-variable-through-tranwrd-function-for-each/m-p/432956#M107284</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-02-01T00:58:04Z</dc:date>
    </item>
  </channel>
</rss>

