<?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 do I create an automatic multi macro? in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-do-I-create-an-automatic-multi-macro/m-p/733774#M38540</link>
    <description>&lt;P&gt;To define a macro you use the %MACRO and %MEND statements.&amp;nbsp; &amp;nbsp;To call a macro you use % in front of the macro name.&amp;nbsp; &lt;FONT face="courier new,courier"&gt;%mymacro()&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To create a macro variable you can use %LET statement or the CALL SYMPUTX() function (do not use the archaic CALL SYMPUT() function unless you really need to have leading and/or trailing spaces added to the value of the macro variable).&amp;nbsp; &amp;nbsp;To reference a macro variable you use &amp;amp; in front of the macro variable's name.&amp;nbsp; &lt;FONT face="courier new,courier"&gt;&amp;amp;myvar.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the values of ID1 are numeric then do not use the QUOTE(TRIM()).&amp;nbsp; &amp;nbsp;But if the values included decimal part or are integers larger than 12 digits then make sure to tell PROC SQL how you want them converting into strings.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select distinct id1 format=best32. into :idlist separated by ' ' from test;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the values of ID1 are numeric and the values of ID are character then you will probably want to first convert ID1 to character string before adding the quotes.&amp;nbsp; Note you also need to worry that the strings in ID are formatted exactly the same as the way you are converting ID1 into strings.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select distinct quote(strip(put(id1,best32.))) into :idlist separated by ' ' from test;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 14 Apr 2021 15:02:49 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-04-14T15:02:49Z</dc:date>
    <item>
      <title>How do I create an automatic multi macro?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-do-I-create-an-automatic-multi-macro/m-p/733762#M38536</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using SAS Enterprise Guide 7.1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a macro that automatically pulls ids from a dataset and then the next bit of code selects the data associated with those ids. The current macro works fine, but only selects 1 id. How do I tweak it to allow multiple values?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On a separate note, I know how to create a list of ids in a macro, but it is manual, by using:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let id = ('123', '456', '789')&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I then add this into my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;WHERE id IN &amp;amp;id.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is it possible to do something similar but automated?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The above code I use in PROC SQL. The code that I am using currently is a data step:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set test;
call symput('id1',id1);
run;

%put _user_;

data test2;
set Cues (where=(id = &amp;amp;id1.));
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Not sure if it possible, maybe there is a different way?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Wed, 14 Apr 2021 14:23:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-do-I-create-an-automatic-multi-macro/m-p/733762#M38536</guid>
      <dc:creator>_SASEG_</dc:creator>
      <dc:date>2021-04-14T14:23:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create an automatic multi macro?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-do-I-create-an-automatic-multi-macro/m-p/733764#M38537</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I am trying to create a macro that automatically pulls ids from a dataset and then the next bit of code selects the data associated with those ids. The current macro works fine, but only selects 1 id. How do I tweak it to allow multiple values?&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Could you provide more explanation, more detail and so on? How would the macro know which IDs to pull from a data set?? Right now you have hard-coded the IDs, that doesn't really help us in designing a macro.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Apr 2021 14:31:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-do-I-create-an-automatic-multi-macro/m-p/733764#M38537</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-04-14T14:31:47Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create an automatic multi macro?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-do-I-create-an-automatic-multi-macro/m-p/733765#M38538</link>
      <description>&lt;P&gt;I don't see any macro code in your example.&amp;nbsp; Did you mean you want to create a macro variable instead of defining a macro?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to put a list of values into a macro variable it is easiest to use the SEPARATED keyword in the INTO clause of the SELECT statement in PROC SQL.&amp;nbsp; So if you have a dataset named TEST with a variable named ID1 you can put all of the values into a single macro variable like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select distinct quote(trim(id1)) into :idlist separated by ' ' from test;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can then use the list of quoted values of ID1 with the IN operator.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;
  set Cues;
  where id = (&amp;amp;idlist.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Apr 2021 14:32:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-do-I-create-an-automatic-multi-macro/m-p/733765#M38538</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-14T14:32:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create an automatic multi macro?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-do-I-create-an-automatic-multi-macro/m-p/733768#M38539</link>
      <description>&lt;P&gt;Thanks for responding &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Apologies, I thought the function symput created a macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your code makes sense. The field I am using for id is actually numeric. How would I alter the code, as I have received the following error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Function TRIM requires a character expression as argument 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 14 Apr 2021 14:46:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-do-I-create-an-automatic-multi-macro/m-p/733768#M38539</guid>
      <dc:creator>_SASEG_</dc:creator>
      <dc:date>2021-04-14T14:46:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create an automatic multi macro?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-do-I-create-an-automatic-multi-macro/m-p/733774#M38540</link>
      <description>&lt;P&gt;To define a macro you use the %MACRO and %MEND statements.&amp;nbsp; &amp;nbsp;To call a macro you use % in front of the macro name.&amp;nbsp; &lt;FONT face="courier new,courier"&gt;%mymacro()&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To create a macro variable you can use %LET statement or the CALL SYMPUTX() function (do not use the archaic CALL SYMPUT() function unless you really need to have leading and/or trailing spaces added to the value of the macro variable).&amp;nbsp; &amp;nbsp;To reference a macro variable you use &amp;amp; in front of the macro variable's name.&amp;nbsp; &lt;FONT face="courier new,courier"&gt;&amp;amp;myvar.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the values of ID1 are numeric then do not use the QUOTE(TRIM()).&amp;nbsp; &amp;nbsp;But if the values included decimal part or are integers larger than 12 digits then make sure to tell PROC SQL how you want them converting into strings.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select distinct id1 format=best32. into :idlist separated by ' ' from test;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the values of ID1 are numeric and the values of ID are character then you will probably want to first convert ID1 to character string before adding the quotes.&amp;nbsp; Note you also need to worry that the strings in ID are formatted exactly the same as the way you are converting ID1 into strings.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select distinct quote(strip(put(id1,best32.))) into :idlist separated by ' ' from test;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Apr 2021 15:02:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-do-I-create-an-automatic-multi-macro/m-p/733774#M38540</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-14T15:02:49Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create an automatic multi macro?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-do-I-create-an-automatic-multi-macro/m-p/733792#M38541</link>
      <description>&lt;P&gt;Thanks so much Tom! Those are great tips!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code now works perfectly!&lt;/P&gt;</description>
      <pubDate>Wed, 14 Apr 2021 15:08:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-do-I-create-an-automatic-multi-macro/m-p/733792#M38541</guid>
      <dc:creator>_SASEG_</dc:creator>
      <dc:date>2021-04-14T15:08:49Z</dc:date>
    </item>
  </channel>
</rss>

