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.

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
  • 596 views
  • 0 likes
  • 2 in conversation