BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
shawn123
Obsidian | Level 7
data array1;
array mark{*} $ mark1-mark5;
array markplusone{*} $ mark6-mark10;
input mark1-mark5;
do i=1 to dim(mark);
markplusone(i)='a'||mark(i);/*different concatenation*/
end;
drop mark1-mark5;
cards;
a b c d e 
;run;

data array1;
array mark{*} $ mark1-mark5;
array markplusone{*} $ mark6-mark10;
input mark1-mark5;
do i=1 to dim(mark);
markplusone(i)=mark(i)||'a'; /*different concatenation*/
end;
drop mark1-mark5;
cards;
a b c d e 
;run;   /*why this concatenation is not working?*/

The picture attached below is for the second code output.

array concatnation.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

So mark1 has length 8. So the value is actually the letter 'a' follow by 7 blanks.

 

Mark6 also has length 8. So when you append the new letter 'a' to mark1, that would make it 9 characters and so the 9th one gets dropped because the length of mark6 is also 8.

 

How about this:

data array1;
array mark{*} $ mark1-mark5;
array markplusone{*} $ mark6-mark10;
input mark1-mark5;
do i=1 to dim(mark);
markplusone(i)=trim(mark(i))||'a'; /*different concatenation*/
end;
/*drop mark1-mark5;*/
cards;
a b c d e 
;run;

or

markplusone(i)=cats(mark(i),'a');

 

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

So mark1 has length 8. So the value is actually the letter 'a' follow by 7 blanks.

 

Mark6 also has length 8. So when you append the new letter 'a' to mark1, that would make it 9 characters and so the 9th one gets dropped because the length of mark6 is also 8.

 

How about this:

data array1;
array mark{*} $ mark1-mark5;
array markplusone{*} $ mark6-mark10;
input mark1-mark5;
do i=1 to dim(mark);
markplusone(i)=trim(mark(i))||'a'; /*different concatenation*/
end;
/*drop mark1-mark5;*/
cards;
a b c d e 
;run;

or

markplusone(i)=cats(mark(i),'a');

 

--
Paige Miller
shawn123
Obsidian | Level 7
Thank you so much, Now I understand!
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
  • 807 views
  • 1 like
  • 2 in conversation