BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8

For each id if acct1 and acct2 have values repeated then how to set them to blank?

id    acct1           Acct2

11    12345        12345    

11    12345        45678

11    12345        45678         

11    23456        23456

12    45678        23456

12    45678        45678

12    56789        56789

11     12345       12345

11                      45678

11

11     23456       23456

12     45678       23456

12                      45678

12     56789       56789

3 REPLIES 3
yoanbolduc
Calcite | Level 5

Hi SASPhile,

proc sort data=inputds out=sortedds;

     by id acct1;

data outputds;

     set sortedds;

     lag_acct1 = lag(acct1);

     if ^first.id then

          if acct1 = lag_acct1 then acct1 = .;

     drop lag_acct1;

run;

And you do the same for acct2.

If the acct1 and acct2 pair doesn't matter, you could simply produce 2 output datasets.

I hope this helps.

Yoan

Astounding
PROC Star

I'm not so sure this is a good idea, but as long as your data are sorted as indicated in the BY statement, it's pretty easy to accomplish:

data want;

set have;

by id acct1 acct2;

if first.acct1=0 then call missing(acct1);

if first.acct2=0 then call missing(acct2);

run;


If the data aren't necessarily sorted, you can add the word NOTSORTED at the end of the BY statement.

Ksharp
Super User

OK.

data have;
input id    acct1           Acct2 ;
cards;
11    12345        12345    
11    12345        45678
11    12345        45678         
11    23456        23456
12    45678        23456
12    45678        45678
12    56789        56789
;
run;
data want;
 set have;
 if id=lag(id) and acct1=lag(acct1) then call missing(acct1);
 if id=lag(id) and acct2=lag(acct2) then call missing(acct2);
run;

Ksharp

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
  • 1068 views
  • 0 likes
  • 4 in conversation