BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Nasser_DRMCP
Lapis Lazuli | Level 10

Hello,

I  have a macro varaible that contains the texte : table1 table2 table3 table4 table5 table6

only table1 and table3 exists in the work librarie

So i would like to get in a macro variable the text table1 table3

thanks in advance for your help

Nasser

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Are those the exact names involved or just generic?

I ask because there are techniques that will work easier with an iterated name than with a list of explicit names.

 

You may need to show us how you are currently creating the macro variable.

 

One approach looks like this:

proc sql;
   select memname into: newlist separated by ' '
   from dictionary.tables
   where libname='WORK'
      and memname in ('TABLE1' 'TABLE2' 'TABLE3')
   ;
quit;

But that would require a quoted list of values. Which likely means doing something with your current value.

Which may require creating a helper macro to quote your existing value or make separately.

View solution in original post

4 REPLIES 4
ballardw
Super User

Are those the exact names involved or just generic?

I ask because there are techniques that will work easier with an iterated name than with a list of explicit names.

 

You may need to show us how you are currently creating the macro variable.

 

One approach looks like this:

proc sql;
   select memname into: newlist separated by ' '
   from dictionary.tables
   where libname='WORK'
      and memname in ('TABLE1' 'TABLE2' 'TABLE3')
   ;
quit;

But that would require a quoted list of values. Which likely means doing something with your current value.

Which may require creating a helper macro to quote your existing value or make separately.

PeterClemmensen
Tourmaline | Level 20

This seems to be part of a bigger problem. What do you want to do with the new macro variable?

Kurt_Bremser
Super User

Store such data in datasets instead of macro variables, and you can use a simple join:

data tables;
input dname $32.;
datalines;
table1
table2
table3
table4
table5
;

proc sql;
create table exist as
  select dname
  from tables t, dictionary.tables d
  where upcase(t.dname) = d.memname and d.libname = "WORK"
;
quit;

 

RexDeus9
Quartz | Level 8

Hi,

 

If I interpret Nasser's question right, I think a blend of the first two answers works just fine:

 

data table1;name='table1';run;
data table2;name='table2';run;
data table3;name='table3';run;
data table4;name='table4';run;
data table5;name='table5';run;

proc sql;
  select memname into: newlist separated by ' '
  from dictionary.tables
  where memname in ('TABLE1' 'TABLE2' 'TABLE3') and libname = "WORK"
;quit;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1101 views
  • 1 like
  • 5 in conversation