BookmarkSubscribeRSS Feed
ikeum
Calcite | Level 5

Hi all,

 

here is my script below:


%let list=;

%macro fix(suffix);

proc sql noprint;
select name into :vars separated by ' '
from dictionary.columns
where upcase(libname)=upcase('work')
and upcase(memname)=upcase('RN_LIST')
and index(name,upcase("&suffix")) ge 1;
quit;

%let list=&list &vars;

%put &list;

%mend fix;

%fix('2019');
%fix('2018');
%fix('2017');

 

I am trying to take variables from the past 3 years.

however it keeps duplicating '2019'

 

Capture.PNG

 

could someone please help to fix it?

 

 

 

3 REPLIES 3
Astounding
PROC Star
It looks like you have been fiddling around with the problem.

That might explain the results.

The calls to the macro should not use quotes:

%fix (2019)
%fix (2018)
%fix (2017)
yabwon
Amethyst | Level 16

Hi @ikeum ,

 

One thing to remember, which may make your macroprogramming easier, macro code operate on texts and treats _everything_ as text so no quotes are needed. In your case when you are passing >>'2019'<< SAS uses all 6 characters: apostrophe, two, zero, one, nine, and apostrophe as macrovariable's value. Do it as @Astounding pointed out, >>2019<<.

 

All the best

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



Kurt_Bremser
Super User

Just to add to what the others already found: you do not need upcase() on libname and memname. These columns are always uppercase in the dictionary tables. But you should use upcase on name

and index(upcase(name),upcase("&suffix")) ge 1

as column names in SAS can be partially or completely lowercase.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—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
  • 3 replies
  • 1044 views
  • 0 likes
  • 4 in conversation