BookmarkSubscribeRSS Feed
podarum
Quartz | Level 8

I'm not sure how to title this but here is what I'm looking for..  I have a series of dups but want only the ones that have a USE = Y, BUT if the dups both have USE = N, keep only one (either one).

I tried this but it didn't work :

if ((first.PS = last.PS) and (first.prov NE last.prov)) then first.USE = 'Y';

HAVE:

PS    PROV  USE

H8G    AB      Y

H8G    AB      N

L1T     ON      Y

M1P    ON     Y

R8A    SK      N

R8A    MB     N

for the R8A keep ONLY one of the 2 even if though USE says N.

WANT:

H8G    AB      Y

H8G    AB      N

L1T     ON      Y

M1P    ON     Y

R8A    SK      Y

R8A    MB     N

6 REPLIES 6
Linlin
Lapis Lazuli | Level 10

proc sort data=have out=want nodupkey;

  by ps use;

run;

podarum
Quartz | Level 8

Linlin, that singled out the R8A but it did not change it to USE=Y

Ksharp
Super User

Can you post some more HAVE WANT?

Why the red part will be changed from N to Y?

podarum
Quartz | Level 8

I would like one of the Dupped N's to cange to Y, because the way they were captured in the earlier steps of data manipulation, where even though R8A is in both Prov's, I want one of the them to be counted, I don't want to lose any PS's.

Linlin
Lapis Lazuli | Level 10

proc sort data=have;

by ps use;

run;

data  single dup;

by ps use;

if first.use and last.use then output single;

    else output dup;

proc sort data= dup  nodupkey;

by ps use;

data dup;

    set dup;

use='Y';

run;

data want;

    set single dup;

run;

podarum
Quartz | Level 8

Great, Thank you

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 6 replies
  • 949 views
  • 3 likes
  • 3 in conversation