BookmarkSubscribeRSS Feed
SVoldrich
Obsidian | Level 7

Situation:

Dr. Smith has 3 addresses, I need to add a counting variable to the end of his name to indicate that all the addresses belong to him.

Dr. Smith 123 Main St

Dr. Smith 45112 East River Rd

Dr. Smith 621 Carnegie Blvd

I need to show the data as

Dr. Smith-001 123 Main St

Dr. Smith-002 45112 East River Rd

Dr. Smith-003 621 Carnegie Blvd

I don't know what this is called to be able to research how to code this.

Thanks in advance!

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

Try this, where name variable contains the dr.smith, and new_name would be with the number:

data inter;

     set have;

     retain cnt;

     by name;

     if _n_=1 or first.name then cnt=1;

     else cnt=cnt+1;

     new_name=strip(name)||put(cnt,z3.);

run;

SVoldrich
Obsidian | Level 7

I'll research that RW9 -

Not everything in that code makes sense to me, but I will research it...

RichardinOz
Quartz | Level 8

I think the term you want is 'Slowly Changing Dimension'.  Typically this would apply where one of the addresses is regarded as current while the others are previous addresses.  Again, typically, there would be 'From' and  'To' dates associated with the records to show the history.  The latest record would have a null 'To' date, or one far in the future such as 31DEC9999.  A separate column might also be used to flag which record is the current one, to simplify queries.

Richard

SVoldrich
Obsidian | Level 7

Richard - Nope, they are all current addresses.

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
  • 4 replies
  • 476 views
  • 0 likes
  • 3 in conversation