BookmarkSubscribeRSS Feed
Aleksandar
Obsidian | Level 7

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
koyelghosh
Lapis Lazuli | Level 10
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).
koyelghosh
Lapis Lazuli | Level 10
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.
Kurt_Bremser
Super User

"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
-----------------------------------------------------------
Kurt_Bremser
Super User

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; 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 4 replies
  • 1189 views
  • 3 likes
  • 3 in conversation