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
Onyx | Level 15

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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 396 views
  • 0 likes
  • 4 in conversation