BookmarkSubscribeRSS Feed
sasphd
Lapis Lazuli | Level 10

Hello, 

I have this table 

 

id variation 

1     0.258

1      -0.53

2       0.563

2       -0.386

2     -0.568

 

I want to calculate the number of negative and positive variations by id. the table that I want 

id variation count

1   positive   1

1   negatif     1

2   positive   1

2   negatif     2

8 REPLIES 8
Reeza
Super User

Use a format.

 

proc format;
value pos_neg_fmt
low - 0 = 'Negative'
0 - high = 'Positive';
run;

proc freq data=have;
table ID*Variation / list;
format variation pos_neg_fmt.;
run;

@sasphd wrote:

Hello, 

I have this table 

 

id variation 

1     0.258

1      -0.53

2       0.563

2       -0.386

2     -0.568

 

I want to calculate the number of negative and positive variations by id. the table that I want 

id variation count

1   positive   1

1   negatif     1

2   positive   1

2   negatif     2


 

sasphd
Lapis Lazuli | Level 10

Thank you very much Reeza. 

How I can do a z-test to test if the proportion of positive variation is equal between id 1 and 2?

sasphd
Lapis Lazuli | Level 10

please can you give the program pour z-test with Anova or ttest

Ksharp
Super User

I think should use Relative Risk . since it is really a contingency table.

@Rick_SAS  wrote a blog about it before.

https://blogs.sas.com/content/iml/2017/07/05/test-equality-two-proportions-sas.html

https://blogs.sas.com/content/iml/2015/10/26/exact-tests-proc-freq.html

https://blogs.sas.com/content/iml/2015/08/21/she-ranger.html

 

 

data have;
input id variation ;
cards;
1     0.258
1      -0.53
2       0.563
2       -0.386
2     -0.568
;

data temp;
 set have;
 sign=sign(variation);
run;
proc freq data=temp noprint;
table id*sign/list out=want;
run;


proc freq data=want;
table id*sign/relrisk riskdiff chisq;
weight count;
run;

 

ballardw
Super User

Just for completeness, where should exactly zero values fit?

sasphd
Lapis Lazuli | Level 10

in positive!

Ksharp
Super User
data have;
input id variation ;
cards;
1     0.258
1      -0.53
2       0.563
2       -0.386
2     -0.568
;

data temp;
 set have;
 sign=sign(variation);
run;
proc freq data=temp noprint;
table id*sign/list out=want;
run;

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand in the Innovate Hub.

Watch Now →
What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 3673 views
  • 6 likes
  • 4 in conversation