BookmarkSubscribeRSS Feed
gyambqt
Obsidian | Level 7

Hi Expert,

 

Is there a way to generate numeric column based on the value a string column.

 

for example, my string column can have the value ABC123 then I want to convert this value into a fixed value 123456 using some SAS functions or format like $hex72.

 

I tried to format the character column using put(column,$hex72.) but it lost precision when I further convert into a numeric column

input(put(column,$72.)).

 

The reason I want to do this is because our primary key is in character format (ABC123) and I need to generate a numeric primary key to represent each primary key.

 

Thanks

2 REPLIES 2
error_prone
Barite | Level 11
Because abc123 ist not the hex-represantation of 123456, you have to explain the logic you want to use.

If you want to extract numbers from strigs, look at prxmatch or substrate with anydigit.
Kurt_Bremser
Super User

Numbers are a VERY BAD IDEA for primary keys. They are limited by the 8-byte real format, which means that any string longer than ~7 bytes will lose accuracy/precision. Stay with character storage.

UUID's can be stored reliably as 16-byte strings (use a $hex32. format for display).

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 903 views
  • 1 like
  • 3 in conversation