Hi there my SAS friends:
I have this table, is an experiment os repeated measures in humans, each human with diferent ages and weights (as response variabel). Here you can see the original table:
Person | Age1 | weight_1 | Age2 | weight_2 | Age3 | weight_3 |
1 | 1672 | 61 | 1714 | 65.4 | 1775 | 51 |
2 | 1671 | 45 | 1713 | 49.2 | 1774 | 46 |
3 | 1670 | 55 | 1712 | 59.4 | 1773 | 44 |
4 | 1670 | 47.2 | 1712 | 50 | 1773 | 42.2 |
5 | 1669 | 50 | 1711 | . | 1772 | 46.1 |
6 | 1668 | 46.2 | 1710 | 50.4 | 1771 | 43.3 |
7 | 1668 | 47 | 1710 | 51 | 1771 | 43 |
8 | 2153 | 48 | 2195 | 54.2 | 2256 | 48.2 |
9 | 2152 | 51 | 2194 | 54 | 2255 | 47 |
10 | 2151 | 56.1 | 2193 | 63.4 | 2254 | 50.1 |
Now, the question is:
HOW CAN I OBTAIN A TABLE LIKE THIS, USINS SAS???
Person | AGE | Age_in_Days | Weight | Weigh_in_grams |
1 | Age1 | 1672 | weight_1 | 61 |
1 | Age2 | 1714 | weight_2 | 65.4 |
1 | Age3 | 1775 | weight_3 | 51 |
2 | Age1 | 1671 | weight_1 | 45 |
2 | Age2 | 1713 | weight_2 | 49.2 |
2 | Age3 | 1774 | weight_3 | 46 |
3 | Age1 | 1670 | weight_1 | 55 |
3 | Age2 | 1712 | weight_2 | 59.4 |
3 | Age3 | 1773 | weight_3 | 44 |
4 | Age1 | 1670 | weight_1 | 47.2 |
4 | Age2 | 1712 | weight_2 | 50 |
4 | Age3 | 1773 | weight_3 | 42.2 |
5 | Age1 | 1669 | weight_1 | 50 |
5 | Age2 | 1711 | weight_2 | 0 |
5 | Age3 | 1772 | weight_3 | 46.1 |
6 | Age1 | 1668 | weight_1 | 46.2 |
6 | Age2 | 1710 | weight_2 | 50.4 |
6 | Age3 | 1771 | weight_3 | 43.3 |
7 | Age1 | 1668 | weight_1 | 47 |
7 | Age2 | 1710 | weight_2 | 51 |
7 | Age3 | 1771 | weight_3 | 43 |
8 | Age1 | 2153 | weight_1 | 48 |
8 | Age2 | 2195 | weight_2 | 54.2 |
8 | Age3 | 2256 | weight_3 | 48.2 |
9 | Age1 | 2152 | weight_1 | 51 |
9 | Age2 | 2194 | weight_2 | 54 |
9 | Age3 | 2255 | weight_3 | 47 |
10 | Age1 | 2151 | weight_1 | 56.1 |
10 | Age2 | 2193 | weight_2 | 63.4 |
10 | Age3 | 2254 | weight_3 | 50.1 |
As you can note, is an special transpose that i'm trying to solve but unhappily i coudlnt make it.
Thanks for your colaboration my SAS friends.
Just build on @Reeza's code:
data want;
set have;
array _age{*} initial_age age1-age3;
array _wgt{*} initial_weight weight1-weight3;
do i=1 to dim(_age);
age = vname(_age{i});
age_in_days = _age{i};
weight = vname(_wgt{i});
weight_in_grams = _wgt{i};
output;
end;
drop i initial_age age1-age3 initial_weight weight1-weight3;
run;
(untested)
This is a Wide to Long Transpose, I prefer the array method to proc transpose in this case, as it's easier and a single step.
http://www.ats.ucla.edu/stat/sas/modules/widetolong_data.htm
data want;
set have;
array _age(3) age1-age3;
array _wgt(3) weight1-weight3;
do i=1 to 3;
age=_age(i);
weight=_wgt(i);
Obs=i;
output;
end;
drop i age1-age3 weight1-weight3;
run;
Thank you so much for your answer, but let me ask you just one more thing, and i hope to be helped too: i added some info to the table:
The Initial_age and the Initial_weight:
Person | AGE | Age_in_Days | Weight | Weigh_in_grams |
1 | Initial_age | 653 | Initial_weight | 30 |
1 | Age1 | 1672 | weight_1 | 61 |
1 | Age2 | 1714 | weight_2 | 65.4 |
1 | Age3 | 1775 | weight_3 | 51 |
2 | Initial_age | 1327 | Initial_weight | 32 |
2 | Age1 | 1671 | weight_1 | 45 |
2 | Age2 | 1713 | weight_2 | 49.2 |
2 | Age3 | 1774 | weight_3 | 46 |
3 | Initial_age | 1123 | Initial_weight | 30 |
3 | Age1 | 1670 | weight_1 | 55 |
3 | Age2 | 1712 | weight_2 | 59.4 |
3 | Age3 | 1773 | weight_3 | 44 |
4 | Initial_age | 1254 | Initial_weight | 33 |
4 | Age1 | 1670 | weight_1 | 47.2 |
4 | Age2 | 1712 | weight_2 | 50 |
4 | Age3 | 1773 | weight_3 | 42.2 |
5 | Initial_age | 1463 | Initial_weight | 45 |
5 | Age1 | 1669 | weight_1 | 50 |
5 | Age2 | 1711 | weight_2 | 0 |
5 | Age3 | 1772 | weight_3 | 46.1 |
6 | Initial_age | 1000 | Initial_weight | 30 |
6 | Age1 | 1668 | weight_1 | 46.2 |
6 | Age2 | 1710 | weight_2 | 50.4 |
6 | Age3 | 1771 | weight_3 | 43.3 |
7 | Initial_age | 1133 | Initial_weight | 12 |
7 | Age1 | 1668 | weight_1 | 47 |
7 | Age2 | 1710 | weight_2 | 51 |
7 | Age3 | 1771 | weight_3 | 43 |
8 | Initial_age | 1000 | Initial_weight | 30 |
8 | Age1 | 2153 | weight_1 | 48 |
8 | Age2 | 2195 | weight_2 | 54.2 |
8 | Age3 | 2256 | weight_3 | 48.2 |
9 | Initial_age | 1000 | Initial_weight | 34 |
9 | Age1 | 2152 | weight_1 | 51 |
9 | Age2 | 2194 | weight_2 | 54 |
9 | Age3 | 2255 | weight_3 | 47 |
10 | Initial_age | 1243 | Initial_weight | 26 |
10 | Age1 | 2151 | weight_1 | 56.1 |
10 | Age2 | 2193 | weight_2 | 63.4 |
10 | Age3 | 2254 | weight_3 | 50.1 |
In this case, how could i make the programation.
Thank you very much
Just build on @Reeza's code:
data want;
set have;
array _age{*} initial_age age1-age3;
array _wgt{*} initial_weight weight1-weight3;
do i=1 to dim(_age);
age = vname(_age{i});
age_in_days = _age{i};
weight = vname(_wgt{i});
weight_in_grams = _wgt{i};
output;
end;
drop i initial_age age1-age3 initial_weight weight1-weight3;
run;
(untested)
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.