Fluorite | Level 6

how to count the number of positive and negative and calculate both of them(mean)

hi all,

I have the data from19961/01/01 to 2014/12/31.

Below is part of my data

 Date Mist(1) 1996-06-20 -0.0027 1996-06-21 0.0026 1996-06-24 0.0042 1996-06-25 0.0045 1996-06-26 0.0018 1996-06-27 0.0016 1996-06-28 -0.0002 1996-07-01 0.0027 1996-07-02 0.0009 1996-07-03 -0.0005 1996-07-04 0.0070

how can i output the chart like this.

thanks all,

Y

1 ACCEPTED SOLUTION

Accepted Solutions
Diamond | Level 26

Re: how to count the number of positive and negative and calculate both of them(mean)

``````data intermediate;
set have;
pos_neg=sign(mist);
run;
proc summary data=intermediate;
class date pos_neg;
var mist;
format date year4.;
output out=want mean= std= n=/autoname;
run;
``````

This code is untested as we cannot write code to work with data that is a screen capture. In the future, please provide code as working SAS data step code (instructions).

--
Paige Miller
2 REPLIES 2
Diamond | Level 26

Re: how to count the number of positive and negative and calculate both of them(mean)

``````data intermediate;
set have;
pos_neg=sign(mist);
run;
proc summary data=intermediate;
class date pos_neg;
var mist;
format date year4.;
output out=want mean= std= n=/autoname;
run;
``````

This code is untested as we cannot write code to work with data that is a screen capture. In the future, please provide code as working SAS data step code (instructions).

--
Paige Miller
Super User

Re: how to count the number of positive and negative and calculate both of them(mean)

Seems simple enough.  What out for testing for negative.  Missing values are considered smaller than any actual value.

Also you did not say which group should include the zeros, so I made them their own group.  You did not say whether or not you wanted NOBS to count the missing values or not.  I decided to exclude them.

``````data have;
input date :yymmdd. mist ;
cards;
1996-06-20 -0.0027
1996-06-21 0.0026
1996-06-24 0.0042
1996-06-25 0.0045
1996-06-26 0.0018
1996-06-27 0.0016
1996-06-28 -0.0002
1996-07-01 0.0027
1996-07-02 0.0009
1996-07-03 -0.0005
1996-07-04 0.0070
;

proc sql ;
create table want as
select year(date) as year
, mean(mist) as mean
, std(mist) as sd
, sum(mist>0) as positive
, sum(not (mist>=0)) as negative
, mean(case when (mist>0) then mist end) as mean_postive
, mean(case when (mist>0) then . else mist end) as mean_negative
, count(mist) as nobs
, sum(mist=0) as zero
, nmiss(mist) as missing
from have
group by year
;
quit;
proc print;
run;
``````

Discussion stats
• 2 replies
• 527 views
• 5 likes
• 3 in conversation