- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 06-24-2019 05:09 AM
(1879 views)
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
4 REPLIES 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Will you please paste the output of PROC MEANS? You have asked PROC MEANS to calculate Median, Minimum and Maximum apart from Mean(Average)?
Is it running or throwing error? If it is running you will have four outputs.. Please paste the log and output (if any).
Is it running or throwing error? If it is running you will have four outputs.. Please paste the log and output (if any).
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I am sorry. I skipped over the fact that it is defined as character. I would have used a DATA step before PROC MEANS and used an informat/format combination to format the Interest_rate as Number(or percentage) from character. Sorry for glossing over the detail in the question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
"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 -----------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;