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

Hi,

 

 I have a dataset with a variable that contains some numbers as "x.y" and others as "x,y".. and I would like to do a univariate analysis on that variable, but sas categorizes the ones with a comma in between as missing. I tried to convert the commas with Commax and comma and numx and nothing seems to Work! Also tried locale but that doesnt make a difference. Please help 🙂 What can be done?

 

Thanks in advance!

Janet

 

 My variable's name is s_result (it's a character and I converted it to numeric). The code is as such:

 

data dist2; set dist (rename=(s_result=s_result_char));

s_result=input(s_result_char, best.);

proc univariate; VAR s_result;

run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Use a conditional input:

data dist2; 
  set dist (rename=(s_result=s_result_char));
  if index(s_result_char,",") then s_result=input(s_result_char,comma.);
  else s_result=input(s_result_char,best.);
run;

proc univariate; 
  var s_result;
run;

Note not tested as no test data in the form of a datastep.  

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Use a conditional input:

data dist2; 
  set dist (rename=(s_result=s_result_char));
  if index(s_result_char,",") then s_result=input(s_result_char,comma.);
  else s_result=input(s_result_char,best.);
run;

proc univariate; 
  var s_result;
run;

Note not tested as no test data in the form of a datastep.  

JanetJanbek
Calcite | Level 5

Thank you SO much. Worked!! 🙂

FreelanceReinh
Jade | Level 19

@JanetJanbek: Please wait. It's possible that your code ran without error messages, but used incorrect values! The COMMA. informat would not treat commas as decimal points. Better use NUMX. and compare the results.

 

 

Edit: Moreover, the COMMA and COMMAX informats have a default length of 1 (not 12 as NUMX.). So, without a length specification (e.g. COMMAX12.) they would read only the first character of the input string.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 1188 views
  • 2 likes
  • 3 in conversation