BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
togglefroggle
Fluorite | Level 6

Hey everyone, I want to add a suffix to all data in a column,

 

 

data have;
INPUT ID $;
DATALINES;
AZ1
AZ2
AZ3
;
RUN;

I'm trying to make the data look like this

ID
AZ1_22 AZ2_22 AZ3_22

I would appreciate any help, thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Since you already have a variable adding additional characters may mean that the suffix/prefix could make the new value too long to fit in the existing variable. So in a new data set you need to do something to make the length long enough to hold the largest expected value.

One way using a Length statement:

data have;
/* read with a fixed 3 characters to create that length*/
INPUT ID $3.;
DATALINES;
AZ1
AZ2
AZ3
;
RUN;

data want;
   /*this length statement adds 3 characters to hold the suffix*/
   length id $ 6.;
   set have;
   id = cats(id,'_22');
run;

The CATS function will remove trailing spaces from values and concatenate values from left to right into a new value.

View solution in original post

1 REPLY 1
ballardw
Super User

Since you already have a variable adding additional characters may mean that the suffix/prefix could make the new value too long to fit in the existing variable. So in a new data set you need to do something to make the length long enough to hold the largest expected value.

One way using a Length statement:

data have;
/* read with a fixed 3 characters to create that length*/
INPUT ID $3.;
DATALINES;
AZ1
AZ2
AZ3
;
RUN;

data want;
   /*this length statement adds 3 characters to hold the suffix*/
   length id $ 6.;
   set have;
   id = cats(id,'_22');
run;

The CATS function will remove trailing spaces from values and concatenate values from left to right into a new value.

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