Dear all,
I have data like this
Interest_rate
1%
3%
4%
6%.
The variable is defined as a character. How to calculate mean?
I have used a function like this and it did not work.
PROC MEANS data=First.Cleaned_data Mean Median Min Max;
var interest_rate;
run;
Thank you in advance.
Aleksandar
"did not work" on its own is useless. Supply the log, example data in usable form, and describe where the result you got differs from your expectations.
As you can see from this
data cleaned_data;
input interest_rate;
format interest_rate percent6.;
datalines;
1
3
4
6
;
PROC MEANS data=Cleaned_data Mean Median Min Max;
var interest_rate;
run;
your code works, as it produces this log:
24 data cleaned_data; 25 input interest_rate; 26 format interest_rate percent6.; 27 datalines; NOTE: The data set WORK.CLEANED_DATA has 4 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.09 seconds cpu time 0.00 seconds 32 ; 33 34 PROC MEANS data=Cleaned_data Mean Median Min Max; 35 var interest_rate; 36 run; NOTE: There were 4 observations read from the data set WORK.CLEANED_DATA. NOTE: The PROCEDURE MEANS printed page 1. NOTE: PROZEDUR MEANS used (Total process time): real time 0.10 seconds cpu time 0.01 seconds
and this result:
Die Prozedur MEANS Analysevariable : interest_rate Mittelwert Median Minimum Maximum ----------------------------------------------------------- 3.5000000 3.5000000 1.0000000 6.0000000 -----------------------------------------------------------
Forget my previous post. I also did not notice that you have a character column (who does such things, in %DEITY's name?).
See this code for how to convert the column in a preceding step:
data cleaned_data;
input interest_rate $;
int_rate_num = input(interest_rate,percent6.) * 100;
datalines;
1%
3%
4%
6%
;
PROC MEANS data=Cleaned_data Mean Median Min Max;
var int_rate_num;
run;
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!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.