Hi, this is a data manipulation exercise. Could you tell me what's wrong with my code for turning numeric variables into character using the following code?
i keep getting messages about undeclared array reference
data have; infile datalines dsd dlm=","; input id $ var1 var2 var3; datalines; a, 34, 45, 12 b, 41, 92, 14 c, 92, 29, 11 ; run; data have1; set have; array var[3] _numeric_; do i=1 to dim[_numeric_]; new[i]=strip(put(var[i], best.)); end; run;
data have;
infile datalines dsd dlm=",";
input id $ var1 var2 var3;
datalines;
a, 34, 45, 12
b, 41, 92, 14
c, 92, 29, 11
;
run;
data want;
set have;
array _old(*) var1-var3;
array _new(*) new_var1-new_var3;
do i=1 to dim(_old);
_new(i) = put(_old(i), best. -l);
end;
drop i;
run;
You have not declared an array named NEW. So you can't assign values to it.
Also, you declare an array named VAR. Later you refer to an array as _VAR, not the same thing. So SAS doesn't like that either.
Could i please receive some help on how to do this?
I'm hitting a brick wall because usually when i do arrays i just use the same variable name as the ones i'm changing, but bc i can't use the same variable name because i'm converting numeric to characer, i don't understand what the solution is.
edit: i changed _var to var in the OP
data have;
infile datalines dsd dlm=",";
input id $ var1 var2 var3;
datalines;
a, 34, 45, 12
b, 41, 92, 14
c, 92, 29, 11
;
run;
data want;
set have;
array _old(*) var1-var3;
array _new(*) new_var1-new_var3;
do i=1 to dim(_old);
_new(i) = put(_old(i), best. -l);
end;
drop i;
run;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: