I am trying to rearrange alphabetically these variables using a macro. But I get an error - Apparent symbolic reference not resolved?
DATA My_data;
INPUT A C Z M L ;
DATALINES;
1 3 26 13 12
;
RUN;
proc sql noprint;
select name into :vars separated by ' '
from dictionary.columns
where libname = 'WORK' and memname = 'My_data'
order by name;
quit;
data My_data_rearranged;
retain &vars;
set My_data;
run;WARNING: Apparent symbolic reference VARS not resolved.
ERROR 22-322: Syntax error, expecting one of the following: a name, ;, _ALL_, _CHARACTER_,
_CHAR_, _NUMERIC_.
ERROR 200-322: The symbol is not recognized and will be ignored.
Always good to look at the ENTIRE log in cases like this:
80 proc sql noprint; 81 select name into :vars separated by ' ' 82 from dictionary.columns 83 where libname = 'WORK' and memname = 'My_data' 84 order by name; NOTE: No rows were selected. 85 quit;
There's the problem. In DICTIONARY.COLUMNS, you have found zero matches. Why? The value of variable memname is always in all capitals, so your code says find memname='My_data' and it doesn't find any matches.
Having said that, why even bother re-arranging columns? It's extra work, but SAS doesn't care, your programs will work regardless of the order of the columns.
where libname = 'WORK' and upper(memname) = 'MY_DATA'
You likely have an empty macro variable because of the case mismatch.
You can test it by adding this line before your data step:
%PUT &vars.;
@DougHold wrote:
I am trying to rearrange alphabetically these variables using a macro. But I get an error - Apparent symbolic reference not resolved?
DATA My_data; INPUT A C Z M L ; DATALINES; 1 3 26 13 12 ; RUN; proc sql noprint; select name into :vars separated by ' ' from dictionary.columns where libname = 'WORK' and memname = 'My_data' order by name; quit; data My_data_rearranged; retain &vars; set My_data; run;WARNING: Apparent symbolic reference VARS not resolved.
ERROR 22-322: Syntax error, expecting one of the following: a name, ;, _ALL_, _CHARACTER_,
_CHAR_, _NUMERIC_.ERROR 200-322: The symbol is not recognized and will be ignored.
Always good to look at the ENTIRE log in cases like this:
80 proc sql noprint; 81 select name into :vars separated by ' ' 82 from dictionary.columns 83 where libname = 'WORK' and memname = 'My_data' 84 order by name; NOTE: No rows were selected. 85 quit;
There's the problem. In DICTIONARY.COLUMNS, you have found zero matches. Why? The value of variable memname is always in all capitals, so your code says find memname='My_data' and it doesn't find any matches.
Having said that, why even bother re-arranging columns? It's extra work, but SAS doesn't care, your programs will work regardless of the order of the columns.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.