BookmarkSubscribeRSS Feed
willy0625
Calcite | Level 5

I have been working with some dataset called test2.

Proc means data=test2;

      var gb_bin;

      class AGE_GP ENQ_3MTS_GB;

      output out=age_3 mean()=;

run;

Analysis Variable : GB_bin

AGE_GP

ENQ_3MTS_GB

N Obs

N

Mean

Std Dev

Minimum

Maximum

18 - 20

0

125

125

0.128

0.335434

0

1

1

10400

10400

0.124808

0.330517

0

1

20 - 22

0

316

316

0.10443

0.306303

0

1

1

10151

10151

0.102552

0.303387

0

1

This is the first few lines of the table generated by the above proc means.

Could anyone please tell me how to transpose this table so that I would obtain a table that looks like 

ENQ_3MTS_GB

0

ENQ_3MTS_GB

1

N obs

Mean

Age_GP

Just to clarify, Age_Gp is a factor with many levels(18-20, 20-22, …) and ENQ_3MTS_GB is a binary variable.

I would like to make sure N obs would show up after I transpose

Many thanks.

2 REPLIES 2
art297
Opal | Level 21

There are a number of ways to accomplish what I think you want.  One way might be something like:

data need;

  set have;

  last_age_gp=lag(age_gp);

  if mod(_n_,2) eq 0 then age_gp=last_age_gp;

run;

proc transpose data=need

   out=temp1 (drop=_:) prefix=n_obs;

  var n_obs;

  id enq_3mts_gb;

  by age_gp notsorted;

run;

proc transpose data=need

   out=temp2 (drop=_:) prefix=mean;

  var mean;

  id enq_3mts_gb;

  by age_gp notsorted;

run;

data want;

  set temp1;

  set temp2;

run;

Ksharp
Super User

You do not give the output.

Also want 1 2 for nobs and mean ...?

nobs_1 nob_2 mean_1 mean_2 ....

Ksharp

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register 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
  • 2 replies
  • 997 views
  • 3 likes
  • 3 in conversation