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!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 288 views
  • 1 like
  • 2 in conversation