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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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