- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.