BookmarkSubscribeRSS Feed
DSW
Calcite | Level 5 DSW
Calcite | Level 5

Suppose that I had a data set that contained a list of names that contained additional columns that group names based on name type (first, last, or middle) and length (short or long):

 

IDNameTypeLengthName
1FirstShortJon
2FirstLongAlexander
3MiddleShortTodd
4MiddleLongWilliam
5LastShortSmith
6LastLong

Stephanopoulos

 

How can I create all unique combinations of names from each of the groups by selecting only 1 first name that is either short or long, 1 middle name that is either short or long, and 1 last name that is either short or long?  For example:

 

JonToddSmith
JonWilliamSmith
JonToddStephanopoulos
JonWilliamStephanopoulos
AlexanderToddSmith
AlexanderWilliamSmith
AlexanderToddStephanopoulos
AlexanderWilliam

Stephanopoulos

 

I thought that proc plan would work but I can't figure out how to do it.  Any help would be greatly appreciated.

1 REPLY 1
ballardw
Super User

Here's one way:

data have;
   informat id best4. NameType $6. Length $5. Name $25.;
   input ID NameType Length Name   ;
datalines;
1 First Short Jon 
2 First Long Alexander 
3 Middle Short Todd 
4 Middle Long William 
5 Last Short Smith 
6 Last Long Stephanopoulos
;
run;


proc sql;
   create table FirstAndMid as
   select a.name as firstName, b.name as Middlename,c.name as Lastname
   from
      (select name from have 
         where Nametype='First') as a,
      (select name from have 
         where Nametype='Middle') as b,
      (select name from have 
         where Nametype='Last') as c
   ;
quit;

   

Note that I basically ignore the length as you didn't have any duplicate names with different lengths within a type.

 

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
  • 1 reply
  • 705 views
  • 1 like
  • 2 in conversation