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.
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;
You do not give the output.
Also want 1 2 for nobs and mean ...?
nobs_1 nob_2 mean_1 mean_2 ....
Ksharp
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.