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!
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.
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.
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!
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.
Ready to level-up your skills? Choose your own adventure.