BookmarkSubscribeRSS Feed
Chiefsfan4ever
Calcite | Level 5

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.

4 REPLIES 4
art297
Opal | Level 21

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.

Chiefsfan4ever
Calcite | Level 5

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?

art297
Opal | Level 21

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

Chiefsfan4ever
Calcite | Level 5

Using the Comma. works.  Thanks a lot Art!

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 4 replies
  • 1823 views
  • 0 likes
  • 2 in conversation