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

Hello,

 

I'am using SAS EG 7.3. I am trying to resolve a macro variable but i didn't. How can i do this? I am trying different two format.

Thank you,

 

/* method-1 */

proc sql noprint;
	select 	count(distinct(name))  into: abc
	from 	dictionary.columns
	where
	libname = 'aaa' and  memname = "%str(%'bbb_&M0.%')" ;
quit;

/* method-2 */

proc sql noprint;
	select 	count(distinct(name))  into: abc
	from 	dictionary.columns
	where
	libname = 'aaa' and  memname = 'bbb_&M0.';
quit;
1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15

Try:

proc sql noprint;
	select 	count(distinct(name))  into: abc
	from 	dictionary.columns
	where
	libname = 'aaa' and  memname = "bbb_&M0.";
quit;

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

4 REPLIES 4
yabwon
Onyx | Level 15

Try:

proc sql noprint;
	select 	count(distinct(name))  into: abc
	from 	dictionary.columns
	where
	libname = 'aaa' and  memname = "bbb_&M0.";
quit;

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



ballardw
Super User

@maozsoy wrote:

Hello,

 

I'am using SAS EG 7.3. I am trying to resolve a macro variable but i didn't. How can i do this? I am trying different two format.

Thank you,

 

/* method-1 */

proc sql noprint;
	select 	count(distinct(name))  into: abc
	from 	dictionary.columns
	where
	libname = 'aaa' and  memname = "%str(%'bbb_&M0.%')" ;
quit;

/* method-2 */

proc sql noprint;
	select 	count(distinct(name))  into: abc
	from 	dictionary.columns
	where
	libname = 'aaa' and  memname = 'bbb_&M0.';
quit;

macro variable values between single quotes do not resolve. So your memname='bbb_&M0.' will not resolve the value.

A quick example:

%let macv = sometext;

%put '&macv.';
%put "&macv.";

The Log will show the second put with the macro variable resolved.

Tom
Super User Tom
Super User

Note that even if you get your macro variables to resolve by using double quotes instead of single quotes, your query will not find any matches.  The MEMNAME and LIBNAME values into the DICTIONARY tables (views) are uppercase only.  So you can never match 'aaa'.

maozsoy
Fluorite | Level 6
Thank you for your warning. Actually memname and libname vars are uppercase in my real code, i just changed in sample code 🙂

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
  • 4 replies
  • 852 views
  • 2 likes
  • 4 in conversation