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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 619 views
  • 2 likes
  • 4 in conversation