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: Call for Content

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!

Submit your idea!

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
  • 2065 views
  • 2 likes
  • 4 in conversation