data have;
input name jan feb mar;
cards;
a 100 200 300
b 100 400
c 100 200
d 500
;
run;
Output Required;
name jan feb mar concat Total
a 100 200 300 janfebmar 600
b 100 400 janmar 500
c 100 200 febmar 300
d 500 mar 500
I tried this i'm getting total. Unable to get concat.
Please help me out. Many thanks.
how about this code.
data have;
input name $ jan feb mar;
cards;
a 100 200 300
b 100 . 400
c . 100 200
d . . 500
;
run;
data want;
set have;
length concat $30;
array avars{3} jan feb mar;
do i=1 to dim(avars);
if avars{i} ne . then concat=cats(concat,vname(avars{3}));
end;
total=sum(of avars{*});
drop i;
run;
Try this
data have;
input name $ jan feb mar;
infile datalines dlm = '|' dsd;
datalines;
a|100|200|300
b|100| |400
c| |100|200
d| | |500
;
data want;
set have;
length concat $ 100;
array m jan feb mar;
do over m;
if m then concat = cats(concat, vname(m));
end;
total = sum(of m[*]);
run;
Result:
name jan feb mar concat total a 100 200 300 janfebmar 600 b 100 . 400 janmar 500 c . 100 200 febmar 300 d . . 500 mar 500
how about this code.
data have;
input name $ jan feb mar;
cards;
a 100 200 300
b 100 . 400
c . 100 200
d . . 500
;
run;
data want;
set have;
length concat $30;
array avars{3} jan feb mar;
do i=1 to dim(avars);
if avars{i} ne . then concat=cats(concat,vname(avars{3}));
end;
total=sum(of avars{*});
drop i;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.