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;
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.
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.
Thank you SO much. Worked!! 🙂
@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.
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!
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.
Ready to level-up your skills? Choose your own adventure.