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.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.