Good Morning All,
I have a large data set that is reading in an excel file that has character and numeric values in the file. The variable names are Var5-Var205 and are charater. I was hoping to write an array-do loop to convert these variables to numeric. I can't seem to figure it out. I've looked for another discussion and can't find anything. If someone knows the solution or has another discussion available, I'd appreciate it.
Have a great day.
How about:
data have;
retain var5-var205 (201*"12");
output;
run;
data want (drop=i in:);
set have (rename=(var5-var205=invar5-invar205));
array in(201) $ invar:;
array var(201);
do i=1 to 201;
var(i)=input(in(i),best12.);
end;
run;
Of course, if you don't need your variables to be labeled "var", you would get rid of the annoying notes in the output.
Art,
I tried doing something similar. Here is what I wrote:
data final;
set test3;
format var305-var505 13.2;
array variable(201) var5-var205;
array new(201) var305-var505;
do i =1 to 201;
new(i)=put(variable(i),13.2);
end;
run;
In multiple rows, I have data like 198,487.33 and it outputs it in the new variable as a period. Same thing happens with code like yours. Thoughts?
Can you attach a file that contains a couple of records from your original file? Your code wouldn't work because you: (1) don't indicate that the first array is going to contain character variables and (2) the correct function to use to convert character to numeric would be input, not put.
I would try it again, but using the code i suggested, but use a comma. informat rather than the best12. or whichever one I had suggested. See: http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000204404.htm
Using the Comma. works. Thanks a lot Art!
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 25. Read more here about why you should contribute and what is in it for you!
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.