BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
nketata
Obsidian | Level 7

Hi all,

 

I have a list of teams with the name of their executive listed first :

Executive: Moe

bob

sarah

Executive2 : Albert

Joan

Rima

Mark

Executive3: Wendy

etc.

I added 2 variables to tag the executives and the teams, so the file looks like

Executive: Moe 1  1

bob             0  1

sarah          0  1

Executive2 : Albert 1 2

Joan            0 2

Rima           0  2

Mark            0 2

Executive3: Wendy   1 3

etc.

I need another varibale associating the name of the executive with their team. I cannot do a proc format because the file is very long and changes very frequently.

 

Executive: Moe 1  1  Executive: Moe 

bob             0  1 Executive: Moe

sarah          0  1 Executive: Moe

Executive2 : Albert  1 2  Executive2 : Albert 

Joan            0 2 Executive2 : Albert 

Rima           0  2 Executive2 : Albert 

Mark            0 2 Executive2 : Albert 

Executive3: Wendy   1 3 Executive3 : Wendy 

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
Use a find function to search for the word executive in the string, if found, assign it to a variable. Use Retain to hold the value across rows, until you change it again.

retain executive;
if find(name, 'Executive')>0 then executive=name;

View solution in original post

3 REPLIES 3
Reeza
Super User
Use a find function to search for the word executive in the string, if found, assign it to a variable. Use Retain to hold the value across rows, until you change it again.

retain executive;
if find(name, 'Executive')>0 then executive=name;
PGStats
Opal | Level 21

Since the executive name is always listed first, simply take the first name of each team and store it in a retained variable

 

data want;
retain;
set have; by team;
length execName $32;
if first.team then execName= name;
run;
PG
nketata
Obsidian | Level 7

Thanks for your input

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