BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jonatan_velarde
Lapis Lazuli | Level 10

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.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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)

PG

View solution in original post

3 REPLIES 3
Reeza
Super User

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;
jonatan_velarde
Lapis Lazuli | Level 10

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

PGStats
Opal | Level 21

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)

PG

sas-innovate-white.png

🚨 Early Bird Rate Extended!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Lock in the best rate now before the price increases on April 1.

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
  • 3 replies
  • 1781 views
  • 0 likes
  • 3 in conversation