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

Hello,

 

I want to modifiy a whole list of variable names in order to add the same suffix to all of them, or only some of them (only the NUMERIC Variables have to get a modified name). I found the following code on the net:

 

/* Create test data */

data one;

input id name :$10. age score1 score2 score3;

datalines;

1 George 10 85 90 89

2 Mary 11 99 98 91

3 John 12 100 100 100

4 Susan 11 78 89 100  ;

run;

 

/* Use PROC SQL to create a macro variable that contains the list of variables to be renamed. */

/* There are 3 examples of PROC SQL statements here to generate macro variables. */

/* Whichever one you choose, you will need to modify the libname and memname (data set name) */

/* values accordingly for your data set. The values need to be in upper case. */

 

/* 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,'_OLD')

into :list

separated by ' '

from dictionary.columns

where libname = 'WORK' and memname = 'ONE';

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 one;

rename &list;

quit;

 

/* Verify the changes with a PROC CONTENTS on your data set. */

proc contents data = work.one;

run;

 

I modified the code to adapt to my programm:

 

data coba_&Jahr11.;

set coba_array;

if Jahr=&Jahr11.;

run;

proc sql noprint;

select cats(name,'=',name,'_&Jahr11.')

into :list

separated by ' '

from dictionary.columns

where libname = 'WORK' and memname = 'COBA_&JAHR11.';

quit;

proc datasets library = work nolist;

modify coba_&Jahr11.;

rename &list;

quit;

proc contents data = work.coba_&Jahr11.;

run;

 

I get the following error message, and obviously it doesn't work. What am I doing wrong?

 

37 proc datasets library = work nolist;

38 modify coba_&Jahr11.;

WARNING: Apparent symbolic reference LIST not resolved.

39 rename &list;

_

2 The SAS System 10:17 Monday, July 22, 2019

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.

40 quit;

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Macro variables must be in quotes that begin and end with a double-quote; it will not work if surrounded by single quotes.

 

where libname = 'WORK' and memname = "COBA_&JAHR11";
--
Paige Miller

View solution in original post

1 REPLY 1
PaigeMiller
Diamond | Level 26

Macro variables must be in quotes that begin and end with a double-quote; it will not work if surrounded by single quotes.

 

where libname = 'WORK' and memname = "COBA_&JAHR11";
--
Paige Miller

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 3405 views
  • 2 likes
  • 2 in conversation