Dear,
I need help in my proc transpose procedure to get output. I am not getting the output I need. Please help in my code.
data one;
input trt $ aebod $ ns;
datalines;
a ca 4
b ca 6
e ca 2
d ca 4
c ge 4
e ge 7
a ge 6
;
proc transpose data=one out=two(drop=_NAME_);
by aebod notsorted;
var NS;
id TRT;
run;
data three;
set two;
array data e a b c d;
do over data;
if missing(data) then data=0;
end;
TOTAL=a+ b+ c+ d;
run;
proc sort data=three;
by aebod;
run;
output getting:
aebod a b c d e Total
ca 4 0 0 0 0 4
ca 0 6 0 0 0 6
ca 0 0 0 4 0 0
ca 0 0 0 0 2 0
ge 6 0 0 0 0 6
ge 0 0 0 0 7 0
output needed:
aebod a b c d e Total
ca 4 6 0 4 2 14
ge 6 0 0 0 7 6
Assuming that your example output for ge was missing one entry, the following would do what you want:
data one; input trt $ aebod $ ns; datalines; a ca 4 b ca 6 e ca 2 d ca 4 c ge 4 e ge 7 a ge 6 ; proc sort data=one; by aebod trt; run; proc transpose data=one out=two(drop=_NAME_); by aebod; var NS; id TRT; run; data two; retain aebod a b c d e; array todo a b c d e; set two; total=sum(a,b,c,d); do over todo; if missing(todo) then todo=0; end; run;
HTH,
Art, CEO, AnalystFinder.com
Thank you for the support. I should have sorted the dataset before transposing. After sorting I got the output needed with my code. Thank you for your code.
Thank you
Your proc tranpsose is incorrect, you need to sort it first if you want that output.
Remove the NOTSORTED option and presort your data.
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.