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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: