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

I have a dataset in which i need to identify the first non missing subject within a dose. 

My data looks like below

 

subject date         dose
10002 1/27/2015 10MG
10002 2/24/2015 10MG
10002 6/1/2015   20MG
10002 9/29/2015 10MG
10002 1/24/2016 10MG

 

I want my final dataset to look like below,

 

subject     date           dose
10002    1/27/2015   10MG
10002    6/1/2015     20MG
10002    9/29/2015   10MG

 

Is there any particular way to do this? If i do first.dose, its giving me only first 2 records of my final dataset. 

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21
data have;
  input subject date mmddyy10. dose $;
  format date mmddyy10.;
  cards;
10002 1/27/2015 10MG
10002 2/24/2015 10MG
10002 6/1/2015   20MG
10002 9/29/2015 10MG
10002 1/24/2016 10MG
;

data want;
  set have;
  by subject dose notsorted;
  if first.dose;
run;

Art, CEO, AnalystFinder.com

View solution in original post

4 REPLIES 4
art297
Opal | Level 21
data have;
  input subject date mmddyy10. dose $;
  format date mmddyy10.;
  cards;
10002 1/27/2015 10MG
10002 2/24/2015 10MG
10002 6/1/2015   20MG
10002 9/29/2015 10MG
10002 1/24/2016 10MG
;

data want;
  set have;
  by subject dose notsorted;
  if first.dose;
run;

Art, CEO, AnalystFinder.com

gp123
Calcite | Level 5

Thanks Art. But this gives me only 2 records.

 

subject     date           dose
10002    1/27/2015   10MG
10002    6/1/2015     20MG

 

I need the first non missing record every time the dose changes.

art297
Opal | Level 21

You're doing something other than what I did. I get all 3 records.

 

Is it possible that you sorted your file before running the code I suggested?

 

Art, CEO, AnalystFinder.com

gp123
Calcite | Level 5

Yes, you are right. I had sorted my dataset before. I corrected it and it gives me 3 records.

 

Thank you very much.

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
  • 2737 views
  • 0 likes
  • 2 in conversation