BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DougHold
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller

View solution in original post

4 REPLIES 4
Reeza
Super User
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.





DougHold
Obsidian | Level 7
Thank you for the tip on testing with %PUT &vars.;
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1072 views
  • 3 likes
  • 3 in conversation