BookmarkSubscribeRSS Feed
YR1415
Calcite | Level 5

I want to convert all the variable types in the table from characters into numerical types.

and here is the sample.

/*The sample dataset TEST contains both character and numeric variables*/
data test;
input id $ b c $ d e $ f;
datalines;
AAA 50 11 1 222 22
BBB 35 12 2 250 25
CCC 75 13 3 990 99
;
run;
/*PROC CONTENTS is used to create an output dataset called VARS to list all*/
/*variable names and their type from the test dataset*/
PROC contents data=test out=vars(keep=name type) noprint;

data vars;
set vars;
if type=2 and name ne'id';
newname=trim(left(name))||"_n";
run;

options symbolgen;
proc sql noprint;
select trim(left(name)),trim(left(newname)),
trim(left(newname))||'='||trim(left(name))
into :c_list separated by '',:n_list separated by '',
:renam_list separated by ''
from vars;
quit;

data test2;
set test;
array ch(*) $ &c_list;
array nu(*) $ &n_list;
do i=1 to dim(ch);
nu(i)=input(ch(i),8.);
end;
drop i &c_list;
rename &renam_list;
run;
proc contents data=test2;
run;

 

But in the code line 'rename &renam_list',

when I run it in the 'log' session, I see the error below:

SYMBOLGEN: Macro variable C_LIST resolves to ce
SYMBOLGEN: Macro variable RENAM_LIST resolves to c_n=ce_n=e
109 rename &renam_list;
NOTE: Line generated by the macro variable "RENAM_LIST".
109 c_n=ce_n=e
_
22
ERROR 22-322: Expecting a name.
 
Could someone help me to solve this problem, what does 'Expecting a name' means in my situation?
 
Tks!!!
1 REPLY 1

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 491 views
  • 2 likes
  • 2 in conversation