hello all,
I'm trying to transpose my variable into observation.
from
name week0 week2 week4
max | 0 | 1106 | 0 |
bijou | 0 | 855 | 344 |
cooper | 70 | 800 | 568 |
princess | 85 | 69 | 688 |
lucy | 92 | 762 | 97 |
and I want the output look like this
name week eos
max week0 0
week2 1106
week4 0
bijou week0 0
week2 855
week4 344
.
.
.
and so on
here is my code
data dogs3;
infile '/folders/myshortcuts/SASUniversityEdition/module 6/dogs3.txt'
firstobs=3
;
input name $ week0 week2 week4;
proc
print data = dogs3;
proc sort data= dogs3;
by name;
proc
transpose data = dogs3
out = newdog3;
by name;
ID week0 week2 week4;
var week0 week2 week4 ;
proc
print data = newdog3;
here is my log
Please try the arrays as below
data have;
input name$ week0 week2 week4 ;
cards;
max 0 1106 0
bijou 0 855 344
cooper 70 800 568
princess 85 69 688
lucy 92 762 97
;
data want;
set have;
array wk week0 week2 week4;
do over wk;
week=vname(wk);
eos=wk;
output;
end;
keep name week eos;
run;
Please try the arrays as below
data have;
input name$ week0 week2 week4 ;
cards;
max 0 1106 0
bijou 0 855 344
cooper 70 800 568
princess 85 69 688
lucy 92 762 97
;
data want;
set have;
array wk week0 week2 week4;
do over wk;
week=vname(wk);
eos=wk;
output;
end;
keep name week eos;
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.