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 open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.