DATA Step, Macro, Functions and more

Creating a character string from different records within a BY group

Reply
N/A
Posts: 0

Creating a character string from different records within a BY group

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
Super Contributor
Super Contributor
Posts: 3,174

Re: Creating a character string from different records within a BY group

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.
Ask a Question
Discussion stats
  • 1 reply
  • 105 views
  • 0 likes
  • 2 in conversation