BookmarkSubscribeRSS Feed
7 REPLIES 7
RW9
Diamond | Level 26 RW9
Diamond | Level 26

What does posting_cat_2 look like.  Post your test data in the form of a datastep so that we can see what you see and assess the best way to achieve this.  If that variable just contains a, b, or c then:

select(posting_cat_2);

  when ('a') ...

...

 

If it contains more, then what happens if more than one appear in the string?  Is there a defining pattern which can identify these uniquely?

 

You may find it simpler to do a quick loop:

do i=1 to lengthn(posting_cat_2);
  if char(posting_cat_2,i) in ('a','b',...) then perf='3) >=...';
end;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Then the simplest way is:

if char(posting_cat_2,1) in ("a","b"...) then ...;

 

Kurt_Bremser
Super User

@RW9 wrote:

Then the simplest way is:

if char(posting_cat_2,1) in ("a","b"...) then ...;

 


or

if scan(posting_cat,1,'.') in ('a','b',...) then ...;

just for adding another option 😉

gamotte
Rhodochrosite | Level 12

Hello,

 

if prxmatch('/[a-j]\./',posting_cat2_new) then ...

Haikuo
Onyx | Level 15

@gamotte wrote:

Hello,

 

if prxmatch('/[a-j]\./',posting_cat2_new) then ...


I like it. I would just tweak a little to make it more robust,

 

if prxmatch('/^[a-j]\./',left(posting_cat2_new)) then ...

 

Astounding
PROC Star

If your sample values are all left-hand justified, you can also use:

 

if posting_cat2_new in : ('a.', 'b.', 'c.', 'd.', 'g.', 'h.', 'k.', 'i.', 'j.') then ...

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 7 replies
  • 2399 views
  • 1 like
  • 6 in conversation