<?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 SAS EG prompts only returning values based on 1 item in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-EG-prompts-only-returning-values-based-on-1-item/m-p/453430#M29233</link>
    <description>&lt;P&gt;I asked this question in the "SAS programming forum" and I was given suggestion to use %let, so I think it might be better to ask here, since I'm actually using SAS EG.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a proc sql query as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select * from table 
where ID in %Bquote('&amp;amp;ID');
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want it to do the equivilant as&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select * from table 
where ID in ('2','3','5';
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I have my prompt set up to accept multiple values but no matter what, it always just filters my results based on the first value ('2').&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want the user to pick ID in the prompts, not in the code itself using the %let&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 12 Apr 2018 02:50:43 GMT</pubDate>
    <dc:creator>mrdlau</dc:creator>
    <dc:date>2018-04-12T02:50:43Z</dc:date>
    <item>
      <title>SAS EG prompts only returning values based on 1 item</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-EG-prompts-only-returning-values-based-on-1-item/m-p/453430#M29233</link>
      <description>&lt;P&gt;I asked this question in the "SAS programming forum" and I was given suggestion to use %let, so I think it might be better to ask here, since I'm actually using SAS EG.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a proc sql query as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select * from table 
where ID in %Bquote('&amp;amp;ID');
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want it to do the equivilant as&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select * from table 
where ID in ('2','3','5';
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I have my prompt set up to accept multiple values but no matter what, it always just filters my results based on the first value ('2').&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want the user to pick ID in the prompts, not in the code itself using the %let&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 02:50:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-EG-prompts-only-returning-values-based-on-1-item/m-p/453430#M29233</guid>
      <dc:creator>mrdlau</dc:creator>
      <dc:date>2018-04-12T02:50:43Z</dc:date>
    </item>
    <item>
      <title>Re: SAS EG prompts only returning values based on 1 item</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-EG-prompts-only-returning-values-based-on-1-item/m-p/453578#M29240</link>
      <description>&lt;P&gt;Easy, but a bit complicated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First of all, make sure that your program is linked to the prompt. If you right-click on Program and select Properties, use the Prompts tab to link the prompt to your program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A good tip is that you can see what macro variables are being set up by the prompt manager by including this line in your program:&lt;/P&gt;
&lt;P&gt;%put _all_; (It will display all of the macro variables in existence.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now in terms of your situation, the SAS prompt manager will set up multiple macro variables. The important ones are (assuming your prompt name is ID):&lt;BR /&gt;ID_COUNT&amp;nbsp;- the count of prompt responses&lt;BR /&gt;ID - the first prompt response&lt;BR /&gt;ID2 through ID5 - the remaining prompt responses (assuming you've entered five prompt responses).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you need a small macro loop to set up your SQL where clause. The following program demonstrates it using SASHELP.SHOES.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro UseID;
	%do i = 1 %to &amp;amp;ID_COUNT;
		%if &amp;amp;i = 1 %then
			%let IDString = "&amp;amp;ID";
		%else %let IDString = &amp;amp;IDString, "&amp;amp;&amp;amp;ID&amp;amp;i";
	%end;

	proc sql;
		select * from sashelp.shoes
			where Region in (&amp;amp;IDString);
	quit;

%mend;

%UseID&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 14:44:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-EG-prompts-only-returning-values-based-on-1-item/m-p/453578#M29240</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2018-04-12T14:44:28Z</dc:date>
    </item>
    <item>
      <title>Re: SAS EG prompts only returning values based on 1 item</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-EG-prompts-only-returning-values-based-on-1-item/m-p/453596#M29242</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/38339"&gt;@mrdlau&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With SAS Enterprise Guide (EG), you may want to start with the Query Builder.&lt;/P&gt;
&lt;P&gt;For the below example, I'm using the SASHELP.CLASS dataset with EG7.1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, I have to create the &lt;STRONG&gt;VALUE&lt;/STRONG&gt; prompt, this is what the &lt;STRONG&gt;Prompt Type and Values&amp;nbsp;&lt;/STRONG&gt;tab looks like.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="prompt.PNG" style="width: 512px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/19746i7933BB4014AD0780/image-size/large?v=v2&amp;amp;px=999" role="button" title="prompt.PNG" alt="prompt.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I'm using a static list but if you want to use a dynamic one, remember your table has to be registered with the metadata. So it's not possible if you use a local server, from an EG perspective.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then moving on to the &lt;STRONG&gt;Query Builder&lt;/STRONG&gt;, based on SASHELP.CLASS.&lt;/P&gt;
&lt;P&gt;After you moved your variables, from the &lt;STRONG&gt;Filter Data&lt;/STRONG&gt; tab, create a new filter (far right icon).&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="FilterData.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/19747i4BB842CE5E8A7E6C/image-size/large?v=v2&amp;amp;px=999" role="button" title="FilterData.PNG" alt="FilterData.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Select the &lt;STRONG&gt;Basic Filter&lt;/STRONG&gt; one, pick Name (in my case) and:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; - &lt;STRONG&gt;In a list&lt;/STRONG&gt; is the operator&lt;/P&gt;
&lt;P&gt;&amp;nbsp; - Check &lt;STRONG&gt;Generate filter for a prompt value&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; - Select the down arrow (on the right) next to &lt;STRONG&gt;Value&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; - From the &lt;STRONG&gt;Prompts&lt;/STRONG&gt; tab, select &amp;amp;value (the prompt we created earlier)&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Filter.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/19748i4B22520D39EB38FD/image-size/large?v=v2&amp;amp;px=999" role="button" title="Filter.PNG" alt="Filter.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Running the Query Builder will allow the user to pick multiple values from the list.&lt;/P&gt;
&lt;P&gt;If I select &lt;EM&gt;Jane&lt;/EM&gt; and &lt;EM&gt;John&lt;/EM&gt; from the prompt,&amp;nbsp;this is the output dataset I get.&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Selection.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/19751i7705492F7EA5C0C3/image-size/large?v=v2&amp;amp;px=999" role="button" title="Selection.PNG" alt="Selection.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Output.PNG" style="width: 485px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/19752iE9B66AE1EE44517A/image-size/large?v=v2&amp;amp;px=999" role="button" title="Output.PNG" alt="Output.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can directly use the clause with a Proc Print for instance:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=sashelp.class;
WHERE %_eg_WhereParam(Name, value, IN, TYPE=S, IS_EXPLICIT=0 );
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope that helps.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Damo&lt;/P&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;
&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>Thu, 12 Apr 2018 14:58:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-EG-prompts-only-returning-values-based-on-1-item/m-p/453596#M29242</guid>
      <dc:creator>Damo</dc:creator>
      <dc:date>2018-04-12T14:58:21Z</dc:date>
    </item>
  </channel>
</rss>

