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

I appologize for the confusion in the titke..  but what I'm trying to achieve is :  I want to shift one field up if a certain criteria is met for the duplicated accounts..

For example:

BEFORE:

Acct   Field_1   Field_2  

001      86            .          

001       .             34    

002      33            21

003      .               .

Make one row for Acct = 001 if the Field_1 is missing and Field_2 is missing for each dupicated account.

AFTER:

Acct   Field_1   Field_2  

001      86            34         

002      33            21

003      .               .

1 ACCEPTED SOLUTION

Accepted Solutions
vasu
Calcite | Level 5

Hi,

Try this.

data before;

input Acct   Field_1   Field_2;

cards;

001      86            .         

001       .            34 

002      33            21

003      .             .

;


proc sort data=before out=before_s;

by acct descending field_1 descending field_2;

run;

data after;

set before_s;

retain field1 field2;

by acct descending field_1 descending field_2;

if first.acct then do;

field1=.;

field2=.;

end;

if not missing (field_1) then field1=field_1;

if not missing (field_2) then field2=field_2;

if last.acct;

run;

View solution in original post

4 REPLIES 4
slchen
Lapis Lazuli | Level 10

Is it what you need?

proc sql;

  select acct, max(field_1) as field_1, max(field_2) as field_2 from yourfile group by acct;

quit;

pradeepalankar
Obsidian | Level 7

hi try this,

data test;

input Acct $3. Field_1   Field_2  ;

cards;

001 86 .

001 . 34

002 33 21

003 . .

;

data test;

update test(obs=0) test;

by acct;

run;

vasu
Calcite | Level 5

Hi,

Try this.

data before;

input Acct   Field_1   Field_2;

cards;

001      86            .         

001       .            34 

002      33            21

003      .             .

;


proc sort data=before out=before_s;

by acct descending field_1 descending field_2;

run;

data after;

set before_s;

retain field1 field2;

by acct descending field_1 descending field_2;

if first.acct then do;

field1=.;

field2=.;

end;

if not missing (field_1) then field1=field_1;

if not missing (field_2) then field2=field_2;

if last.acct;

run;

podarum
Quartz | Level 8

Thanks vasu.. this is exactly what I was looking for.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 831 views
  • 1 like
  • 4 in conversation