Obsidian | Level 7

## How can i can concatnate Variable according to their values?

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Rhodochrosite | Level 12

## Re: How can i can concatnate Variable according to their values?

``````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;``````
2 REPLIES 2
Tourmaline | Level 20

## Re: How can i can concatnate Variable according to their values?

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  ```

Rhodochrosite | Level 12

## Re: How can i can concatnate Variable according to their values?

``````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;``````
Discussion stats
• 2 replies
• 547 views
• 2 likes
• 3 in conversation