BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SSK_011523
Calcite | Level 5

Hi all, 

I'm interested in BR-based regimens in the following code. I wish to keep all patient ids.

I'm not sure how to proceed

IDREGIMENLOTregimen12
1A1LChemo monotherapy
1 2L 
1 3L 
2B1LChemo monotherapy
2 2L 
2 3L 
3C+D1LBR-based
3 2L 
3 3L 
4C+D1LBR-based
4 2L 
4 3L 
5E1LChemo monotherapy
5F2LChemo monotherapy
5E+F3LOther chemotherapy
5G1Lonco
5 2L 
5 3L 
6C+D1LBR-based
6 2L 
6 3L 

 

Data want - 

IDREGIMENLOTregimen12
3C+D1LBR-based
3 2L 
3 3L 
4C+D1LBR-based
4 2L 
4 3L 
6C+D1LBR-based
6 2L 
6 3L 
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
CODE NOT TESTED:

proc sql;
create table want as
select * from have
where ID in (select ID from have where regimen12='BR-based')
;
quit;

View solution in original post

4 REPLIES 4
Ksharp
Super User
CODE NOT TESTED:

proc sql;
create table want as
select * from have
where ID in (select ID from have where regimen12='BR-based')
;
quit;
SSK_011523
Calcite | Level 5

Thank you! this code works. 

I QC'ed it too. 

yabwon
Onyx | Level 15

Two more options along with the one proposed by @Ksharp 

data have;
infile cards dlm="|";
input ID REGIMEN :$3. LOT $2. regimen12 :$30.;
cards;
1|A|1L|Chemo monotherapy
1| |2L| 
1| |3L| 
2|B|1L|Chemo monotherapy
2| |2L| 
2| |3L| 
3|C+D|1L|BR-based
3| |2L| 
3| |3L| 
4|C+D|1L|BR-based
4| |2L| 
4| |3L| 
5|E|1L|Chemo monotherapy
5|F|2L|Chemo monotherapy
5|E+F|3L|Other chemotherapy
5|G|1L|onco
5| |2L| 
5| |3L| 
6|C+D|1L|BR-based
6| |2L| 
6| |3L| 
;
run;
proc print;
run;

/* option 1 */
data want;
  do _N_=1 by 1 until(last.ID);
    set have;
    by ID notsorted;
    output+(regimen12="BR-based");
  end;

  do _N_=1 to _N_;
    set have;
    if output then output;
  end;
  output=0;
  drop output;
run;
proc print;
run;

/* option 2 */
data want2;
  declare hash H(dataset:"have(where=(regimen12='BR-based'))");
  H.defineKey("ID");
  H.defineDone();

  do until(eof);
    set have end=eof;
    if 0=H.check() then output;
  end;
stop;
run;
proc print;
run;

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



yabwon
Onyx | Level 15

and since IDs are numerical in "limited" range, one more:

/* option 3 */
data want3;
  
  array IDs[1:100] _temporary_;
  do until(eof1);
    set have(keep=ID regimen12) end=eof1;
    where regimen12='BR-based';
    IDs[ID]=1;
  end;

  do until(eof2);
    set have end=eof2;
    if IDs[ID] then output;
  end;
stop;
run;
proc print;
run;
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 4 replies
  • 637 views
  • 0 likes
  • 3 in conversation