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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.