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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 855 views
  • 0 likes
  • 2 in conversation