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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.