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

This could probably be the really novice task but i am unable to get the answer easily.

My EMP table looks like this

Emp_NameAddressPhoneDept
abc 1234
abcpark road
abc Sales

What I want in output is single observation like

Emp_NameAddressPhoneDept
abcpark road1234Sales

Need direction please

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You can also do the same thing by merging:

data have;

  infile datalines dlm="," dsd;

  input Emp_Name $ Address $ Phone $ Dept $;

datalines;

abc,,1234,

abc,park road,,

abc,,,Sales

;

run;

data want;

  merge have (keep=emp_name address where=(address ne ""))

        have (keep=emp_name phone where=(phone ne ""))

        have (keep=emp_name dept where=(dept ne ""));

  by emp_name;

run;

View solution in original post

3 REPLIES 3
Astounding
PROC Star

It's short, but understanding it might require some study on your part.  Assuming your data set is sorted by EMP_NAME:

data want;

   update emp (obs=0) emp;

   by emp_name;

run;

Good luck.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

You can also do the same thing by merging:

data have;

  infile datalines dlm="," dsd;

  input Emp_Name $ Address $ Phone $ Dept $;

datalines;

abc,,1234,

abc,park road,,

abc,,,Sales

;

run;

data want;

  merge have (keep=emp_name address where=(address ne ""))

        have (keep=emp_name phone where=(phone ne ""))

        have (keep=emp_name dept where=(dept ne ""));

  by emp_name;

run;

normarc
Calcite | Level 5

This is a very simple example.   My question is what business rules do you want to employ when you find something like multiple address for a given employee?   If you had something like a status/update date, then perhaps you could sort on that to help choose?

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
  • 857 views
  • 6 likes
  • 4 in conversation