BookmarkSubscribeRSS Feed
mesujit
Calcite | Level 5

I have a small querry on below data set:
- where ever there are multiple entries of siteid, i have to keep the only one entry which has sitestatus as 'open' and siterole as 'PI', other rows of same siteid i have to delete.
Please help me to code it.
i am trying , but loosing some or the other required lines.

 

==== input data set====
siteidsiteStatussiterole
544openPI
544BusyPI
565closed or BusyPI
567openPI
543closedPI
543openPI
   
==== output data set should be====
siteidsiteStatussiteRrole
544openPI
565closed or BusyPI
567openPI
543openPI
3 REPLIES 3
novinosrin
Tourmaline | Level 20

Hi @mesujit  Can you please clarify why the following is in the output?

565 closed or Busy PI

 

data have;
input siteid	(siteStatus	siterole) ( & $15.);
cards;
544	open	PI
544	Busy	PI
565	closed or Busy	  PI
567	open	PI
543	closed	PI
543	open	PI
;

proc sql;
 create table want(drop=_n_) as
 select *,(siteStatus='open' and siterole='PI') as _n_
 from have
 group by siteid
 having _n_ or max(_n_)=0;
quit;

 

mesujit
Calcite | Level 5

Hi Novinosrin,

its because the site status is not confirmed.. cant be considered as open.

PeterClemmensen
Tourmaline | Level 20
data have;
input siteid siteStatus $ 5-19 siterole $;
datalines;
544 open           PI
544 Busy           PI
565 closed or Busy PI
567 open           PI
543 closed         PI
543 open           PI
;

data want;
   do _N_ = 1 by 1 until (last.siteid);
      set have;
      by siteid notsorted;
   end;
   do until (last.siteid);
      set have;
      by siteid notsorted;
      if _N_ = 1 | siteStatus = "open" then output;
   end;
run;

Result:

 

siteid siteStatus     siterole 
544    open           PI 
565    closed or Busy PI 
567    open           PI 
543    open           PI 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1086 views
  • 0 likes
  • 3 in conversation