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'
could someone please help to fix it?
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
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.