BookmarkSubscribeRSS Feed
altijani
Quartz | Level 8

Hello 

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?

 

Here is my data

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;

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.

 

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;
3 REPLIES 3
Amir
PROC Star

Hi @altijani,

 

Have you tried changing the single quotes (') that surround the call to %_eg_WhereParam to double quotes (")?

 

Thanks & kind regards,

Amir.

Tom
Super User Tom
Super User

Is STORE_NUM a string?  Do the value literally start with a percent sign?  If not then none of your WHEN expressions will ever be true.

 

The macro processor ignores text in strings bounded on the outside by single quotes.

Try using double quotes.

Turn on MPRINT option to see what SAS code the %_EG_WHEREPARAM() macro generates for your input values.

altijani
Quartz | Level 8

The STORE_NUM is a string that does not start with %

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1276 views
  • 0 likes
  • 3 in conversation