<?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 Prompts in CASE statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Prompts-in-CASE-statement/m-p/749589#M235586</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using SAS EG to run a prompt, which provides the output I need if I don't add the "CASE" statement. However, I need to use the same prompt to create a new variable that identify the category of the store once flagged. In other words, the prompt will check and see if the store number I entered exist and produce a data called "QUERY_HAVE". I also want the data "QUERY_HAVE" to identify the category that it found this number of the store: whether it was selling, shipping, or billing?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my data&lt;/P&gt;&lt;PRE&gt;data have;
input year Quarter store_num $ shipping_num $ Billing_num $ sales;
datalines;
2020 1 A1 . A1 520
2020 1 A2 A1 . 15
2020 1 A3 A2 A3 753
2020 2 A1 . A3 662
2020 2 A2 A1 A2 779
2020 3 A1 . A1 895
2020 3 A2 A2 A2 1012
2020 3 A3 A3 A1 1128
2020 4 A2 A1 A3 1245
2020 4 A3 A3 . 1361
;
run;&lt;/PRE&gt;&lt;P&gt;Here is the code I am using to combine the prompt and the creation of the new variable "Store_Category". The results I am getting is what I would expect for the prompt if I don't add the "CASE" statement. However, when I use the "CASE" statement, then the store category is all blank with no data in it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE WORK.QUERY_HAVE AS
SELECT t1.year,
t1.Quarter,
t1.store_num,
t1.shipping_num,
t1.Billing_num,
/* Store_Category */
(Case
When t1.Store_NUM = (%unquote('%_eg_WhereParam( t1.store_num, Stores, IN, TYPE=S, IS_EXPLICIT=0 )')) then 'Selling'
When t1.Shipping_NUM = (%unquote('%_eg_WhereParam( t1.shipping_num, Stores, IN, TYPE=S, IS_EXPLICIT=0 )')) then 'Shipping'
When t1.Billing_NUM = (%unquote('%_eg_WhereParam( t1.Billing_num, Stores, IN, TYPE=S, IS_EXPLICIT=0 )')) then 'Billing'
Else ''
end) AS Store_Category,
t1.sales
FROM WORK.HAVE t1
WHERE %_eg_WhereParam( t1.store_num, Stores, IN, TYPE=S, IS_EXPLICIT=0 ) OR %_eg_WhereParam( t1.shipping_num,
Stores, IN, TYPE=S, IS_EXPLICIT=0 ) OR %_eg_WhereParam( t1.Billing_num, Stores, IN, TYPE=S, IS_EXPLICIT=0 );
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 22 Jun 2021 15:17:01 GMT</pubDate>
    <dc:creator>altijani</dc:creator>
    <dc:date>2021-06-22T15:17:01Z</dc:date>
    <item>
      <title>Prompts in CASE statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Prompts-in-CASE-statement/m-p/749589#M235586</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using SAS EG to run a prompt, which provides the output I need if I don't add the "CASE" statement. However, I need to use the same prompt to create a new variable that identify the category of the store once flagged. In other words, the prompt will check and see if the store number I entered exist and produce a data called "QUERY_HAVE". I also want the data "QUERY_HAVE" to identify the category that it found this number of the store: whether it was selling, shipping, or billing?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my data&lt;/P&gt;&lt;PRE&gt;data have;
input year Quarter store_num $ shipping_num $ Billing_num $ sales;
datalines;
2020 1 A1 . A1 520
2020 1 A2 A1 . 15
2020 1 A3 A2 A3 753
2020 2 A1 . A3 662
2020 2 A2 A1 A2 779
2020 3 A1 . A1 895
2020 3 A2 A2 A2 1012
2020 3 A3 A3 A1 1128
2020 4 A2 A1 A3 1245
2020 4 A3 A3 . 1361
;
run;&lt;/PRE&gt;&lt;P&gt;Here is the code I am using to combine the prompt and the creation of the new variable "Store_Category". The results I am getting is what I would expect for the prompt if I don't add the "CASE" statement. However, when I use the "CASE" statement, then the store category is all blank with no data in it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE WORK.QUERY_HAVE AS
SELECT t1.year,
t1.Quarter,
t1.store_num,
t1.shipping_num,
t1.Billing_num,
/* Store_Category */
(Case
When t1.Store_NUM = (%unquote('%_eg_WhereParam( t1.store_num, Stores, IN, TYPE=S, IS_EXPLICIT=0 )')) then 'Selling'
When t1.Shipping_NUM = (%unquote('%_eg_WhereParam( t1.shipping_num, Stores, IN, TYPE=S, IS_EXPLICIT=0 )')) then 'Shipping'
When t1.Billing_NUM = (%unquote('%_eg_WhereParam( t1.Billing_num, Stores, IN, TYPE=S, IS_EXPLICIT=0 )')) then 'Billing'
Else ''
end) AS Store_Category,
t1.sales
FROM WORK.HAVE t1
WHERE %_eg_WhereParam( t1.store_num, Stores, IN, TYPE=S, IS_EXPLICIT=0 ) OR %_eg_WhereParam( t1.shipping_num,
Stores, IN, TYPE=S, IS_EXPLICIT=0 ) OR %_eg_WhereParam( t1.Billing_num, Stores, IN, TYPE=S, IS_EXPLICIT=0 );
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Jun 2021 15:17:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Prompts-in-CASE-statement/m-p/749589#M235586</guid>
      <dc:creator>altijani</dc:creator>
      <dc:date>2021-06-22T15:17:01Z</dc:date>
    </item>
    <item>
      <title>Re: Prompts in CASE statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Prompts-in-CASE-statement/m-p/749606#M235594</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/130872"&gt;@altijani&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have you tried changing the single quotes (') that surround the call to&amp;nbsp;%_eg_WhereParam to double quotes (")?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 15:44:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Prompts-in-CASE-statement/m-p/749606#M235594</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2021-06-22T15:44:19Z</dc:date>
    </item>
    <item>
      <title>Re: Prompts in CASE statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Prompts-in-CASE-statement/m-p/749614#M235598</link>
      <description>&lt;P&gt;Is STORE_NUM a string?&amp;nbsp; Do the value literally start with a percent sign?&amp;nbsp; If not then none of your WHEN expressions will ever be true.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro processor ignores text in strings bounded on the outside by single quotes.&lt;/P&gt;
&lt;P&gt;Try using double quotes.&lt;/P&gt;
&lt;P&gt;Turn on MPRINT option to see what SAS code the %_EG_WHEREPARAM() macro generates for your input values.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 15:58:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Prompts-in-CASE-statement/m-p/749614#M235598</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-22T15:58:17Z</dc:date>
    </item>
    <item>
      <title>Re: Prompts in CASE statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Prompts-in-CASE-statement/m-p/749618#M235602</link>
      <description>&lt;P&gt;The&amp;nbsp;&lt;SPAN&gt;STORE_NUM is a string that does not start with %&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 16:13:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Prompts-in-CASE-statement/m-p/749618#M235602</guid>
      <dc:creator>altijani</dc:creator>
      <dc:date>2021-06-22T16:13:12Z</dc:date>
    </item>
  </channel>
</rss>

