BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,

I'm trying to string together all values for a particular character variable that are observed within a BY group. For example, if i have the following data for the three observations within a BY group:

id1 aa
id2 bb
id3 cc

How would I create a character string variable with the value "aa-bb-cc" that would be reported as such for all three observations within the BY group?
Thanks so much,
NG
1 REPLY 1
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Create a second file with the BY var list, using a DATA step, and define a RETAIN statement for the "concatenated string" variable. You will want to explore using the FIRST. and LAST. technique to assign or concatenate (either using || or !! for your concatenation operator), creating your new variable. Then use a DATA step MERGE process to combine your original file with the second file, placing your new variable back on the original file, as needed.

You can search the SAS support http://support.sas.com/ website using the Google advanced argument below to find related SAS-hosted documentation and other technical reference papers on the subject:

data step by processing first last site:sas.com


Scott Barry
SBBWorks, Inc.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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