<?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: Passing a Name with a &amp;quot;Last Name, First Name&amp;quot; format from a data step into a macro wit in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Passing-a-Name-with-a-quot-Last-Name-First-Name-quot-format-from/m-p/649998#M194905</link>
    <description>&lt;P&gt;You're welcome. Anyways, It was your solution that needed a slight adjustment. I wouldn't want to take that credit away from you.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 22 May 2020 19:54:08 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-05-22T19:54:08Z</dc:date>
    <item>
      <title>Passing a Name with a "Last Name, First Name" format from a data step into a macro with Call execute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-a-Name-with-a-quot-Last-Name-First-Name-quot-format-from/m-p/649968#M194891</link>
      <description>&lt;P&gt;I am using a data step (although I could use proc sql)&amp;nbsp; to run through a list of names and generate a report.&lt;/P&gt;&lt;P&gt;the names are "Last Name, First Name".&lt;/P&gt;&lt;P&gt;I am getting: "ERROR: More positional parameters found than defined."&lt;/P&gt;&lt;P&gt;Here is sample code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/SPAN&gt; namelist;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s2"&gt;input&lt;/SPAN&gt; ID GRP &lt;SPAN class="s3"&gt;$4.&lt;/SPAN&gt; NAME &lt;SPAN class="s3"&gt;$25.&lt;/SPAN&gt; ;&lt;/P&gt;&lt;P class="p2"&gt;datalines&lt;SPAN class="s4"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;01 ABCD Smith, John&lt;/P&gt;&lt;P class="p1"&gt;02 WXYZ Jones, Dorothy&lt;/P&gt;&lt;P class="p1"&gt;03 MNOP Garcia, Kimberly&lt;/P&gt;&lt;P class="p1"&gt;;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;&lt;STRONG&gt;%MACRO&lt;/STRONG&gt;&lt;/SPAN&gt; test_Report(ID, GRP, NAME);&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s2"&gt;%put&lt;/SPAN&gt; ID;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s2"&gt;%put&lt;/SPAN&gt; &amp;amp;GRP;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s2"&gt;%put&lt;/SPAN&gt; &amp;amp;NAME;&lt;/P&gt;&lt;P class="p4"&gt;&lt;STRONG&gt;%MEND&lt;/STRONG&gt;&lt;SPAN class="s4"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p2"&gt;&lt;SPAN class="s1"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/SPAN&gt; _NULL_&lt;SPAN class="s4"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p5"&gt;&lt;SPAN class="s2"&gt;set&lt;/SPAN&gt;&lt;SPAN class="s4"&gt; namelist; &lt;/SPAN&gt;/* columns are ID Group and Name */&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s2"&gt;call&lt;/SPAN&gt; execute( &lt;SPAN class="s5"&gt;'%test_Report('&lt;/SPAN&gt; || strip(ID) || &lt;SPAN class="s5"&gt;','&lt;/SPAN&gt; || strip(GRP)&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;|| &lt;SPAN class="s5"&gt;','&lt;/SPAN&gt; || &lt;SPAN class="s2"&gt;%bquote&lt;/SPAN&gt;(NAME) || &lt;SPAN class="s5"&gt;');'&lt;/SPAN&gt; );&lt;/P&gt;&lt;P class="p4"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;SPAN class="s4"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What am I missing? There has to be a simple way of doing this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;Stan&lt;/P&gt;</description>
      <pubDate>Fri, 22 May 2020 17:59:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-a-Name-with-a-quot-Last-Name-First-Name-quot-format-from/m-p/649968#M194891</guid>
      <dc:creator>SSTEAD</dc:creator>
      <dc:date>2020-05-22T17:59:20Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a Name with a "Last Name, First Name" format from a data step into a macro wit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-a-Name-with-a-quot-Last-Name-First-Name-quot-format-from/m-p/649987#M194897</link>
      <description>&lt;P&gt;You will need the macro invocation to mask the commas in the passed argument.&amp;nbsp; This is most often done with %STR().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you want the requested code to be executed to look like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%test_Report( &amp;lt;ID&amp;gt;, &amp;lt;GRP&amp;gt;, %STR(&amp;lt;LAST&amp;gt;,&amp;lt;FIRST&amp;gt;) )&lt;/PRE&gt;
&lt;P&gt;Very often CALL EXECUTE statements are desired to have their submissions all occur after the DATA step completes.&amp;nbsp; &amp;nbsp;This can be accomplished by wrapping the submitted code in %NRSTR().&amp;nbsp; So the 'dispatching'&amp;nbsp;&lt;SPAN style="font-family: inherit;"&gt;data _null_ would be&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data _NULL_;
  set namelist; /* columns are ID Group and Name */&lt;BR /&gt;&lt;BR /&gt;  * compute source code for macro invocation;
  macro_call_source_code = 
    '%test_report('
    || catx (',',  ID, GRP, '%str(' || NAME || ')' )    /* wrap name in %STR source code to allow comma containing argument to be passed */
    || ')'
  ;
&lt;BR /&gt;  * submit computed source code;
  call execute( '%nrstr(' || trim(macro_call_source_code) || ')' );
run;
 &lt;/PRE&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;</description>
      <pubDate>Fri, 22 May 2020 19:07:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-a-Name-with-a-quot-Last-Name-First-Name-quot-format-from/m-p/649987#M194897</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-05-22T19:07:16Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a Name with a "Last Name, First Name" format from a data step into a macro wit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-a-Name-with-a-quot-Last-Name-First-Name-quot-format-from/m-p/649990#M194898</link>
      <description>&lt;P&gt;If the macro is expected to get names that contain commas then write the macro in a way that it is expecting the values provided to have quotes.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO test_Report(ID, GRP, NAME);
%local name2;
%put ID value is &amp;amp;ID;
%put GRP value is &amp;amp;GRP;
%put NAME with quotes is &amp;amp;NAME;
%let name2=%sysfunc(dequote(&amp;amp;name));
%put NAME without qutoes is &amp;amp;NAME2;
%MEND;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then provide the quotes in the call.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _NULL_;
  set namelist; /* columns are ID Group and Name */
  file code;
  put '%test_Report('  id= ',' grp= ',' name= :$quote. ')';
run;
%include code / source2;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 May 2020 19:15:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-a-Name-with-a-quot-Last-Name-First-Name-quot-format-from/m-p/649990#M194898</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-05-22T19:15:47Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a Name with a "Last Name, First Name" format from a data step into a macro wit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-a-Name-with-a-quot-Last-Name-First-Name-quot-format-from/m-p/649991#M194899</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/44387"&gt;@SSTEAD&lt;/a&gt;&amp;nbsp; slight adjustment to the syntax you used&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _NULL_;

set namelist; /* columns are ID Group and Name */

call execute
('%nrstr(%test_Report('||catx(',',ID,GRP,cat('%bquote(',NAME,')'))||'))');

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some notes:&lt;/P&gt;
&lt;P&gt;1. Your idea of&amp;nbsp;&lt;SPAN class="s2"&gt;%bquote&lt;/SPAN&gt;&lt;SPAN&gt;(NAME) is very smart indeed. However you are better off&amp;nbsp; delaying the execution of the macro call until after the datastep is complete.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;2. Therefore you would need the %nrstr to delay the macro statements execution as the call can independently execute without having to bother with the datastep compiler.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;3. In my humble opinion, it is better to not marry macro processor and execution unless absolutely needed, albeit the marriage most likely will end in a divorce.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 May 2020 19:39:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-a-Name-with-a-quot-Last-Name-First-Name-quot-format-from/m-p/649991#M194899</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-05-22T19:39:45Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a Name with a "Last Name, First Name" format from a data step into a macro wit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-a-Name-with-a-quot-Last-Name-First-Name-quot-format-from/m-p/649996#M194903</link>
      <description>Thank you so much. This works perfectly. I frequently use a data step to generate a list of MACRO calls that I then include, similar to one of the other replies.</description>
      <pubDate>Fri, 22 May 2020 19:52:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-a-Name-with-a-quot-Last-Name-First-Name-quot-format-from/m-p/649996#M194903</guid>
      <dc:creator>SSTEAD</dc:creator>
      <dc:date>2020-05-22T19:52:14Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a Name with a "Last Name, First Name" format from a data step into a macro wit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-a-Name-with-a-quot-Last-Name-First-Name-quot-format-from/m-p/649997#M194904</link>
      <description>Thank you. This works well and is pretty easy to understand. It does create another variable, but is very clear.</description>
      <pubDate>Fri, 22 May 2020 19:53:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-a-Name-with-a-quot-Last-Name-First-Name-quot-format-from/m-p/649997#M194904</guid>
      <dc:creator>SSTEAD</dc:creator>
      <dc:date>2020-05-22T19:53:23Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a Name with a "Last Name, First Name" format from a data step into a macro wit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-a-Name-with-a-quot-Last-Name-First-Name-quot-format-from/m-p/649998#M194905</link>
      <description>&lt;P&gt;You're welcome. Anyways, It was your solution that needed a slight adjustment. I wouldn't want to take that credit away from you.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 May 2020 19:54:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-a-Name-with-a-quot-Last-Name-First-Name-quot-format-from/m-p/649998#M194905</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-05-22T19:54:08Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a Name with a "Last Name, First Name" format from a data step into a macro wit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-a-Name-with-a-quot-Last-Name-First-Name-quot-format-from/m-p/649999#M194906</link>
      <description>Thank you. I frequently use this trick. I like the ability to review what was written and check it for debugging, and did this earlier in development.</description>
      <pubDate>Fri, 22 May 2020 19:54:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-a-Name-with-a-quot-Last-Name-First-Name-quot-format-from/m-p/649999#M194906</guid>
      <dc:creator>SSTEAD</dc:creator>
      <dc:date>2020-05-22T19:54:40Z</dc:date>
    </item>
  </channel>
</rss>

