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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 4 replies
  • 1952 views
  • 0 likes
  • 2 in conversation