BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
RandiRyterman
Fluorite | Level 6

I have a SAS dataset with a variable called LENGTH, which describe the length of a fishing line.  But some of the values have a ',' instead of a '.' to designate a decimal point, so SAS read this variable as a character variable.  How do I replace all ',' with '.' and convert the variable to numeric?

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Use TRANSLATE to replace the commas with periods.

var_char = translate(var_char, ".", ",");

 

USE INPUT to convert character to numeric 

Var_Num = input(var_char, best12.);

View solution in original post

4 REPLIES 4
Reeza
Super User

Use TRANSLATE to replace the commas with periods.

var_char = translate(var_char, ".", ",");

 

USE INPUT to convert character to numeric 

Var_Num = input(var_char, best12.);
Ksharp
Super User

Canyou post some data?

 

Var_Num = input(var_char, ??  best12.);
Patrick
Opal | Level 21

If you're reading the data from a text file then you could also do something like below:

proc format;
  invalue mixedComma
    low-high = [comma.]
    other    = [commax.]
  ;
quit;

data test;
  infile datalines dsd dlm=' ' truncover;
  input var :mixedComma.;
  datalines;
10.2
10,2
10
;
run;
Ksharp
Super User

Patrick,

I would do this.

 

data test;
  infile datalines dsd dlm=' ' truncover;
  input var $;
  if find(var,',') then fmt='commax32.';
   else fmt='best32.    ';
  new=inputn(var,fmt);
  datalines;
10.2
10,2
10
;
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 2168 views
  • 2 likes
  • 4 in conversation