BookmarkSubscribeRSS Feed
KaraG
Fluorite | Level 6

Hi everyone, 

I'm trying to add a suffix to all column names in a dataset. I'm following the code (example 2) here. I have never used proc SQL before. The first portion of the code (the sql part) seems to run ok (no error messages). When I run the second part (proc datasets), I get the following messages: 

 

86 proc datasets library = work nolist;
87 modify meanCPUAbottomfish;
WARNING: Apparent symbolic reference LIST not resolved.
88 rename &list; run;
_
22
76
NOTE: Enter RUN; to continue or QUIT; to end the procedure.
 
ERROR 22-322: Expecting a name.
 
ERROR 76-322: Syntax error, statement will be ignored.
 
NOTE: Statements not processed because of errors noted above.
89 quit; 
 
How do I fix this error? Thanks. 
3 REPLIES 3
Reeza
Super User
It's saying your macro variable list doesn't exist.
Please show how you created the macro variable, the log and the output from the following, before the PROC DATASETS proc:

%put &list.;

KaraG
Fluorite | Level 6
Hi, thank you so much for replying. I actually just tried the code again with the dataset name capitalized and it worked...?

Here's the code:
/* Example 1: */
/* This code creates a macro variable &list with the list of variables in the form. */
/* id = id_OLD */
/* This format could be used to add a suffix to all the variables. */
proc sql noprint;
select cats(name,'=',name,'_bottom')
into :list
separated by ' '
from dictionary.columns
where libname = 'WORK' and memname = 'MEANCPUABOTTOMFISH';
quit;
*/
/* Use PROC DATASETS to do the rename using the macro variable you have created. */
/* Modify the libref and data set name for your data set. */;
proc datasets library = work nolist;
modify meanCPUAbottomfish;
rename &list; run;
quit;
/* Verify the changes with a PROC CONTENTS on your data set. */
proc contents data = MEANCPUABOTTOMFISH;
run;
Reeza
Super User
That is correct, if you look in Dictionary.Columns table it always stores the libname and memname in upper case letters.
Happy to hear your issue is resolved.

A somewhat safer method in the long run is to up case your comparison all the time, but that can add some extra time to the query.

libname = upper('WORK') and memname = upper('MEANCPUABOTTOMFISH');

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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
  • 3 replies
  • 3398 views
  • 3 likes
  • 2 in conversation