BookmarkSubscribeRSS Feed
SASdevAnneMarie
Barite | Level 11

Hello Experts,

 

I'm trying reorganise my data with proc sql : I count tne number of supports by NO_C, in case of 2 I would like to chose the Major if it's present :

input:

SASdevAnneMarie_0-1678745253650.png

Want:

SASdevAnneMarie_1-1678745306552.png

I'm wondering how I can use if prxmatch("m/MAJORATION/oi",lb_sup)> 0 condition in proc sql ?

 

Thank you !

1 REPLY 1
SASKiwi
PROC Star

This is a bit ugly but here is one way based on limited data. I don't think PRXMATCH is the best option here even if it does work in SQL (I haven't tried).

data have;
  input @1 NO_C $6.
        @8 lb_sup $10.
		@19 nb_supp 2.
		@21 top_supp_major 2.
		;
datalines;
JO2886 MINIMUM    2  0
JO2886 MAJORATION 2  1
B00405 MAJORATION 2  1
B00405 ACTIV1     2  0
B00867 ACTIV1     2  0
;
run;

proc sql;
  create table want as
  select *
  from have
  where top_supp_major = 1
  or (NO_C in 
      (select NO_C
       from have
       where top_supp_major = 0
       except
       select NO_C
       from have
       where top_supp_major = 1
      )
     );
quit;

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of 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
  • 1 reply
  • 401 views
  • 0 likes
  • 2 in conversation