BookmarkSubscribeRSS Feed
karthigao
Fluorite | Level 6

I want to use the where function with like operators for data sub setting but the activity can contain anything like poultry processing, poultry slaughter, Meat processing, meat slaughter and so on, now i have to resolve the macro to poultry masking only the % sign?  Example of the code is given below, which function is best in this situation?

%let activity= Poultry;

PROC SQL outobs= 500 NOPRINT;

  create table work.testdata as

     select var1, var2, activities

  from retailstore

  where activities like "%&activity%"

;

QUIT;

the activity variable contains the following value

Poultry processing, Meat Processing, Poultry slaughter

Poultry slaughter, Meat Processing

Ready to eat Poultry, Poultry slaughter

Meat Processing, Import

Meat slaughter, Import, Meat Processing

Ready to eat meat, Meat Processing

Import

4 REPLIES 4
mohamed_zaki
Barite | Level 11

give example of your data specially the activity col

karthigao
Fluorite | Level 6

activity

Poultry processing, Meat Processing, Poultry slaughter

Poultry slaughter, Meat Processing

Ready to eat Poultry, Poultry slaughter

Meat Processing, Import

Meat slaughter, Import, Meat Processing

Ready to eat meat, Meat Processing

Import

This may occur in any combination, out of which i want to extract either poultry, meat, export, import to find out how many poultry centers (processing, slaughter, ready to eat), how many meat centers, and import, expor

Ksharp
Super User

An alternative way is symget()

where  find(activities,symget('activity') )

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Agree with KSharp there.  A further alternative is to put your items in a table and subquery that.  E.g:

data activities;

     activity="Poultry Processing"; output;

      activity="Meat processing"; output;

...

run;

proc sql;

     select   *

     from     HAVE

     where   ACTIVITY in (select distinct ACTIVITY from ACTIVITIES);

quit;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 809 views
  • 3 likes
  • 4 in conversation