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;
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 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.