<?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 add keyword parameters into a command/string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-keyword-parameters-into-a-command-string/m-p/508110#M136420</link>
    <description>&lt;P&gt;I guess that the use case will not be limited to select * logic only.&lt;/P&gt;
&lt;P&gt;I would try to use transtrn() function, to replace (or in this case insert table alias and commas).&lt;/P&gt;
&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%sysfunc(transtrn(%str( &amp;amp;vars.),%str( ),%str( b.)))&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 28 Oct 2018 13:52:19 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2018-10-28T13:52:19Z</dc:date>
    <item>
      <title>how to add keyword parameters into a command/string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-keyword-parameters-into-a-command-string/m-p/508087#M136403</link>
      <description>&lt;P&gt;So I am writing a macro that might have some keyword parameters. Here is an example of the action which I want to do. I want to&amp;nbsp;take variables X and Y from dataset1 . But if there are some variables specified for the keyword parameters (e.g. vars=A B C), I want to take those variables too. How do I tell SAS to add these values&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro merge_dataset(vars=);&lt;BR /&gt;proc sql;&lt;BR /&gt; create table output&lt;BR /&gt; as select distinct a.date, a.ID,&lt;BR /&gt; b.date, b.ID, b.X,b.Y, /*here is where I want to add "b.A, b.B, b.C,"/*&lt;BR /&gt; from dataset1 as a, dataset2 as b&lt;BR /&gt; where a.date=b.date&lt;BR /&gt; and a.ID=b.ID;&lt;BR /&gt; quit;&lt;BR /&gt;%mend;&lt;BR /&gt;%merge_dataset(vars=A B C);&lt;/PRE&gt;&lt;P&gt;One way to solve this is to put in a condition such as :&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;If %vars. ne then do; .......;.end;
else do; ......;end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But this is too long.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 28 Oct 2018 08:08:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-add-keyword-parameters-into-a-command-string/m-p/508087#M136403</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2018-10-28T08:08:45Z</dc:date>
    </item>
    <item>
      <title>Re: how to add keyword parameters into a command/string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-keyword-parameters-into-a-command-string/m-p/508093#M136409</link>
      <description>&lt;P&gt;you can simply try the b.*, here the * will consider all the variables from dataset2. So you don't actually require the macro.&lt;/P&gt;
&lt;P&gt;but you cannot consider the same variables from dataset1 and dataset2 else we will get the warning. Here in the code since date and id are coming from dataset1 and if we are using b.* from dataset2, the same date and id variables will come from b as well hence we need to remove a.date and a.id, since they are in dataset2 as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;&lt;BR /&gt; create table output&lt;BR /&gt; as select distinct &lt;BR /&gt; b.*&lt;BR /&gt; from dataset1 as a, dataset2 as b&lt;BR /&gt; where a.date=b.date&lt;BR /&gt; and a.ID=b.ID;&lt;BR /&gt; quit;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 28 Oct 2018 09:36:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-add-keyword-parameters-into-a-command-string/m-p/508093#M136409</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2018-10-28T09:36:05Z</dc:date>
    </item>
    <item>
      <title>Re: how to add keyword parameters into a command/string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-keyword-parameters-into-a-command-string/m-p/508110#M136420</link>
      <description>&lt;P&gt;I guess that the use case will not be limited to select * logic only.&lt;/P&gt;
&lt;P&gt;I would try to use transtrn() function, to replace (or in this case insert table alias and commas).&lt;/P&gt;
&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%sysfunc(transtrn(%str( &amp;amp;vars.),%str( ),%str( b.)))&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 28 Oct 2018 13:52:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-add-keyword-parameters-into-a-command-string/m-p/508110#M136420</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2018-10-28T13:52:19Z</dc:date>
    </item>
    <item>
      <title>Re: how to add keyword parameters into a command/string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-keyword-parameters-into-a-command-string/m-p/508266#M136482</link>
      <description>&lt;P&gt;Yes, that works if I want all variables in b, but what if I don't want all variables? one solution is to create a DATA step before the SQL and create dataset b that contains all wanted variables.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Oct 2018 08:40:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-add-keyword-parameters-into-a-command-string/m-p/508266#M136482</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2018-10-29T08:40:41Z</dc:date>
    </item>
    <item>
      <title>Re: how to add keyword parameters into a command/string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-keyword-parameters-into-a-command-string/m-p/508272#M136486</link>
      <description>&lt;P&gt;can you please elaborate? for example, how do I use this in my example?&lt;/P&gt;</description>
      <pubDate>Mon, 29 Oct 2018 08:56:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-add-keyword-parameters-into-a-command-string/m-p/508272#M136486</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2018-10-29T08:56:04Z</dc:date>
    </item>
    <item>
      <title>Re: how to add keyword parameters into a command/string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-keyword-parameters-into-a-command-string/m-p/508493#M136570</link>
      <description>&lt;P&gt;Directly where you want it (untested, but that's your task).&lt;/P&gt;</description>
      <pubDate>Mon, 29 Oct 2018 19:50:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-add-keyword-parameters-into-a-command-string/m-p/508493#M136570</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2018-10-29T19:50:17Z</dc:date>
    </item>
  </channel>
</rss>

