BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MSK4
Obsidian | Level 7

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
japelin
Rhodochrosite | Level 12

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;

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

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  

 

japelin
Rhodochrosite | Level 12

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;

SAS Innovate 2025: Register Now

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 644 views
  • 2 likes
  • 3 in conversation