-1

I am looking to automate a process which has a sales dataset and a specific column named SALES CODE which is of 5 letters. Based on the input given by the user I would like to filter the data but the problem is the user can give multiple sales codes and sometimes the length of codes could be 5,4,3,2 or 1 based on the condition. How will I filter out the required rows based on the above condition?

SALESCODE area value units rep
A10AA            KR     100 10     Jay
B10AQ            TN     120 12     Jrn 
C10AH            KR     200 10     Jay
T11TA             TR     180 10     Jay

Say if I give the input as A10AA, B10A, T11 I should be able to

Get the sales data with codes A10AA, B10AQ, T11TA. kindly help.

Filburt
  • 17,626
  • 12
  • 64
  • 115
San
  • 1
  • 2
    What have you tried ? What errors did you get ? Did you try using the input as the basis of a statement using the prefix in operator (`IN:`) ? From Docs on "SAS Operators in Expressions", *Note: You can add a colon (:) modifier to any of the operators to compare only a specified prefix of a character string. See Character Comparisons for details.* How about as the basis of a `prxmatch` pattern where the inputs commas are changed to regex alternation operator `|` ? – Richard Jun 24 '19 at 09:11

1 Answers1

1

Use the IN operator. Since you want to match values that start with the specified value use the : modifier. Since your values are character values make sure to include quotes.

proc print data=sales_data ;
  where salescode in: ("A10AA" "B10A" "T11");
run;

If you want you can use commas between the values in the list, but I find it easier to type spaces instead.

Tom
  • 47,574
  • 2
  • 16
  • 29