BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
david27
Quartz | Level 8

Hello,

Please advise.

%let exception=b_n1h1 c_n1h1 f_n1h1 m_n1h1;
%let have=(n1h2_output*((n1h1_n1h2*((a_n1h1*a[i]-b[1]) + (b_n1h1*b[i]-b[1]) + (c_n1h1*c[i]-b[1]) + (d_n1h1*d[i]-b[1]) + 
(e_n1h1*e[i]-b[1]) + (f_n1h1*f[i]-b[1]) + (g_n1h1*g[i]-b[1]))-b[2]);

I want a list of all values(anything that has an underscore) from 'have' that are NOT in 'exception'

 

want==n1h2_output n1h1_n1h2 a_n1h1 d_n1h1 e_n1h1 g_n1h1

Thank You

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hi @david27  Please see if this works. I just took a quick stab at your string with some easy assumptions-

%let exception=b_n1h1 c_n1h1 f_n1h1 m_n1h1;
%let have=(n1h2_output*((n1h1_n1h2*((a_n1h1*a[i]-b[1]) + (b_n1h1*b[i]-b[1]) + (c_n1h1*c[i]-b[1]) + (d_n1h1*d[i]-b[1]) + 
(e_n1h1*e[i]-b[1]) + (f_n1h1*f[i]-b[1]) + (g_n1h1*g[i]-b[1]))-b[2]);

data have;
  have="&have";
run;
data want;
 set have;
 array ex(4)$30 _temporary_('b_n1h1' 'c_n1h1' 'f_n1h1' 'm_n1h1');
 do _n_=1 to countw(have,'*');
  w=scan(have,_n_,'*');
  want=scan(w,-1);
  if index(want,'_') and want not in ex then output;
 end;
 drop w;
run;
have want
(n1h2_output*((n1h1_n1h2*((a_n1h1*a[i]-b[1]) + (b_n1h1*b[i]-b[1]) + (c_n1h1*c[i]-b[1]) + (d_n1h1*d[i]-b[1]) + (e_n1h1*e[i]-b[1]) + (f_n1h1*f[i]-b[1]) + (g_n1h1*g[i]-b[1]))-b[2]) n1h2_output
(n1h2_output*((n1h1_n1h2*((a_n1h1*a[i]-b[1]) + (b_n1h1*b[i]-b[1]) + (c_n1h1*c[i]-b[1]) + (d_n1h1*d[i]-b[1]) + (e_n1h1*e[i]-b[1]) + (f_n1h1*f[i]-b[1]) + (g_n1h1*g[i]-b[1]))-b[2]) n1h1_n1h2
(n1h2_output*((n1h1_n1h2*((a_n1h1*a[i]-b[1]) + (b_n1h1*b[i]-b[1]) + (c_n1h1*c[i]-b[1]) + (d_n1h1*d[i]-b[1]) + (e_n1h1*e[i]-b[1]) + (f_n1h1*f[i]-b[1]) + (g_n1h1*g[i]-b[1]))-b[2]) a_n1h1
(n1h2_output*((n1h1_n1h2*((a_n1h1*a[i]-b[1]) + (b_n1h1*b[i]-b[1]) + (c_n1h1*c[i]-b[1]) + (d_n1h1*d[i]-b[1]) + (e_n1h1*e[i]-b[1]) + (f_n1h1*f[i]-b[1]) + (g_n1h1*g[i]-b[1]))-b[2]) d_n1h1
(n1h2_output*((n1h1_n1h2*((a_n1h1*a[i]-b[1]) + (b_n1h1*b[i]-b[1]) + (c_n1h1*c[i]-b[1]) + (d_n1h1*d[i]-b[1]) + (e_n1h1*e[i]-b[1]) + (f_n1h1*f[i]-b[1]) + (g_n1h1*g[i]-b[1]))-b[2]) e_n1h1
(n1h2_output*((n1h1_n1h2*((a_n1h1*a[i]-b[1]) + (b_n1h1*b[i]-b[1]) + (c_n1h1*c[i]-b[1]) + (d_n1h1*d[i]-b[1]) + (e_n1h1*e[i]-b[1]) + (f_n1h1*f[i]-b[1]) + (g_n1h1*g[i]-b[1]))-b[2]) g_n1h1

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

Hi @david27  Please see if this works. I just took a quick stab at your string with some easy assumptions-

%let exception=b_n1h1 c_n1h1 f_n1h1 m_n1h1;
%let have=(n1h2_output*((n1h1_n1h2*((a_n1h1*a[i]-b[1]) + (b_n1h1*b[i]-b[1]) + (c_n1h1*c[i]-b[1]) + (d_n1h1*d[i]-b[1]) + 
(e_n1h1*e[i]-b[1]) + (f_n1h1*f[i]-b[1]) + (g_n1h1*g[i]-b[1]))-b[2]);

data have;
  have="&have";
run;
data want;
 set have;
 array ex(4)$30 _temporary_('b_n1h1' 'c_n1h1' 'f_n1h1' 'm_n1h1');
 do _n_=1 to countw(have,'*');
  w=scan(have,_n_,'*');
  want=scan(w,-1);
  if index(want,'_') and want not in ex then output;
 end;
 drop w;
run;
have want
(n1h2_output*((n1h1_n1h2*((a_n1h1*a[i]-b[1]) + (b_n1h1*b[i]-b[1]) + (c_n1h1*c[i]-b[1]) + (d_n1h1*d[i]-b[1]) + (e_n1h1*e[i]-b[1]) + (f_n1h1*f[i]-b[1]) + (g_n1h1*g[i]-b[1]))-b[2]) n1h2_output
(n1h2_output*((n1h1_n1h2*((a_n1h1*a[i]-b[1]) + (b_n1h1*b[i]-b[1]) + (c_n1h1*c[i]-b[1]) + (d_n1h1*d[i]-b[1]) + (e_n1h1*e[i]-b[1]) + (f_n1h1*f[i]-b[1]) + (g_n1h1*g[i]-b[1]))-b[2]) n1h1_n1h2
(n1h2_output*((n1h1_n1h2*((a_n1h1*a[i]-b[1]) + (b_n1h1*b[i]-b[1]) + (c_n1h1*c[i]-b[1]) + (d_n1h1*d[i]-b[1]) + (e_n1h1*e[i]-b[1]) + (f_n1h1*f[i]-b[1]) + (g_n1h1*g[i]-b[1]))-b[2]) a_n1h1
(n1h2_output*((n1h1_n1h2*((a_n1h1*a[i]-b[1]) + (b_n1h1*b[i]-b[1]) + (c_n1h1*c[i]-b[1]) + (d_n1h1*d[i]-b[1]) + (e_n1h1*e[i]-b[1]) + (f_n1h1*f[i]-b[1]) + (g_n1h1*g[i]-b[1]))-b[2]) d_n1h1
(n1h2_output*((n1h1_n1h2*((a_n1h1*a[i]-b[1]) + (b_n1h1*b[i]-b[1]) + (c_n1h1*c[i]-b[1]) + (d_n1h1*d[i]-b[1]) + (e_n1h1*e[i]-b[1]) + (f_n1h1*f[i]-b[1]) + (g_n1h1*g[i]-b[1]))-b[2]) e_n1h1
(n1h2_output*((n1h1_n1h2*((a_n1h1*a[i]-b[1]) + (b_n1h1*b[i]-b[1]) + (c_n1h1*c[i]-b[1]) + (d_n1h1*d[i]-b[1]) + (e_n1h1*e[i]-b[1]) + (f_n1h1*f[i]-b[1]) + (g_n1h1*g[i]-b[1]))-b[2]) g_n1h1
david27
Quartz | Level 8

Thank You for the code @novinosrin 

Can this be done without a datastep?

 

Also not sure if this helps but,

the string that i am looking for

  • has an underscore
  • begins with ( and ends with *
  • is not in exception list.
novinosrin
Tourmaline | Level 20

Hi @david27  "Without a datastep makes it more a heavier syntax in my opinion-



 options minoperator mindelimiter=' ';
%macro t;
 %global want;
 %let want=;
 %let exception=b_n1h1 c_n1h1 f_n1h1 m_n1h1;
 %let have=(n1h2_output*((n1h1_n1h2*((a_n1h1*a[i]-b[1]) + (b_n1h1*b[i]-b[1]) + (c_n1h1*c[i]-b[1]) + (d_n1h1*d[i]-b[1]) + 
(e_n1h1*e[i]-b[1]) + (f_n1h1*f[i]-b[1]) + (g_n1h1*g[i]-b[1]))-b[2]);
 %do i=1 %to %sysfunc(countw(%bquote(&have),%str(*)));
  %let w=%scan(%bquote(&have),&i,%str(*));
  %let need=%scan(%bquote(&w),-1);
  %put &=need;
  %if %index(&need,%str(_))>0 and %eval(&need  in (&exception))=0  %then %let want=&want &need;
 %end;
%mend t;
%t

%put &=want;

LOG:

       %put &=want;
WANT=n1h2_output n1h1_n1h2 a_n1h1 d_n1h1 e_n1h1 g_n1h1
david27
Quartz | Level 8
You were correct. Data step is better. Also it’s more flexible.
Thank You very much.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 4 replies
  • 1208 views
  • 1 like
  • 2 in conversation