BookmarkSubscribeRSS Feed
NagendraBS
Fluorite | Level 6

Hi all,

 

I have one dataset as below,

 

MBR_ID DATE PTYPE MBR REGION
100097538 15-Jan-18 PTR GOLD AMRC
100097538 22-Jan-18 PTR GOLD AMRC
100097538 31-Jan-18 PTR PLTN AMRC

 

Now i need the new flag based on ID Date and MBR as below

 

MBR_ID DATE PTYPE MBR REGION Flag
100097538 15-Jan-18 PTR GOLD AMRC 1
100097538 22-Jan-18 PTR GOLD AMRC 1
100097538 31-Jan-18 PTR PLTN AMRC 0

 

Can you please help on this using sas 

 

Thanks in Advance.

 

Nagendra 

2 REPLIES 2
ballardw
Super User

"First" what?

You logic is not actually clear as the MBR=PLAT is the "first" MBR value for the date 31-Jan-18. So it really doesn't appear that "date" is that important from the very small sample provided.

You may need to show an example, which can be made up, but provides more examples that would clarify the rule(s) involved.

 

I can write code that would solve this particular example but would be very unlikely to extend to other combinations of dates or MBR values correctly.

Reeza
Super User

Making assumptions, if this doesn't work, explain why in detail and show cases where it doesn't work.

 

proc sort data=have;
by mbr_id mbr;
run;

data want;
set have;
by mbr_id mbr;

flag = not(first.mbr and last.mbr);

run;

@NagendraBS wrote:

Hi all,

 

I have one dataset as below,

 

MBR_ID DATE PTYPE MBR REGION
100097538 15-Jan-18 PTR GOLD AMRC
100097538 22-Jan-18 PTR GOLD AMRC
100097538 31-Jan-18 PTR PLTN AMRC

 

Now i need the new flag based on ID Date and MBR as below

 

MBR_ID DATE PTYPE MBR REGION Flag
100097538 15-Jan-18 PTR GOLD AMRC 1
100097538 22-Jan-18 PTR GOLD AMRC 1
100097538 31-Jan-18 PTR PLTN AMRC 0

 

Can you please help on this using sas 

 

Thanks in Advance.

 

Nagendra 


 

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 711 views
  • 1 like
  • 3 in conversation