BookmarkSubscribeRSS Feed
VonNeuman
Calcite | Level 5

Hi, I'm moving my first steps in Sas base programming. I'm trying to figure out how to solve the following problem:

 

id        group_id                          id        group_id

1           13456                            1          13456C

2           12345         --------->      2          12345C

3           34567                            3          34567C

 

So, in nutshell, I want to add a character to an entire dataset variable.

Thanks

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Is group_id a numeric variable?  If so you can't, you cannot put non numeric characters in a numeric field.  Now you can move this to a character field:

data want (drop=old_group_id);
  length group_id $50;
  set have (rename=(group_id=old_group_id));
  group_id=cats(put(old_group_id,best.),"C");
run;

If group_id is character then:

data want;
  set have;
  group_id=cats(group_id,"C");
run;
rivieralad
Obsidian | Level 7
Hi,
Depends whether your existing values are held as numeric or character variables.
If character then look at the CATS function.
If numeric then look at the PUT function to with a suitable format to convert to character first and then the CATS function.
Hope this helps.
Cheers
Chris

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
  • 2 replies
  • 15718 views
  • 2 likes
  • 3 in conversation