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.
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
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
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.
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
Yes, you are right. I had sorted my dataset before. I corrected it and it gives me 3 records.
Thank you very much.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.