BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi- I'm wondering if a macro can be written that concatenates comments into one comment field. For example, the code below concatenates 8 comment fields. However, the maximum number of comments can change each time it is run, so I want it to be flexible so that if the maximum number of comments changes from 8 to 10, it will concatenate all 10 comment fields. Any help would be greatly appreciated!

data dat2 (keep=compyr fnlcomment);
set wide;
fnlcomment=cmt1||' '||cmt2||' '||cmt3||' '||cmt4||' '||cmt5||' '||cmt6||' '||cmt7||' '||cmt8;
run;
1 REPLY 1
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
The code below demonstrates one string concatenation technique when the variables have a stem value:

data _null_;
retain cmnt1-cmnt5 'xyz';
length fullcmt $100;
fullcmt = catx(' ',of cmnt: );
putlog _all_;
run;

Another approach when a stem variable prefix is not available, consider using an ARRAY and a DO I=1 TO DIM(); END; to concatenate each individual variable, referenced as an array component.

Scott Barry
SBBWorks, Inc.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 789 views
  • 0 likes
  • 2 in conversation