BookmarkSubscribeRSS Feed
doylejm
Fluorite | Level 6

Hi all,

I have longitudinal monthly data and want to use only those rows of data for an ID where all 12 months in a year are available. So for the following, I want to exclude 11/2005 and 12/2005 for ID=49, and exclude 1/2007 and 2/2007 for ID=80.

I would really appreciate some suggestions - I experimented with first.ID and last.ID to no avail.Thanx. jm.

 

ID date year month ret
49 1-Nov-05 2005 11 2.65188
49 1-Dec-05 2005 12 0.0682
49 1-Jan-06 2006 1 0.4771
49 1-Feb-06 2006 2 0.90218
49 1-Mar-06 2006 3 0.97459
49 1-Apr-06 2006 4 0.42076
49 1-May-06 2006 5 -2.65363
49 1-Jun-06 2006 6 -0.46042
49 1-Jul-06 2006 7 0.2505
49 1-Aug-06 2006 8 2.3988
49 1-Sep-06 2006 9 2.42167
49 1-Oct-06 2006 10 2.24773
49 1-Nov-06 2006 11 0.98223
49 1-Dec-06 2006 12 0.81832
80 1-Jan-06 2006 1 3.29777
80 1-Feb-06 2006 2 -0.37559
80 1-Mar-06 2006 3 0.94251
80 1-Apr-06 2006 4 1.12045
80 1-May-06 2006 5 -2.67775
80 1-Jun-06 2006 6 0.09488
80 1-Jul-06 2006 7 0.85308
80 1-Aug-06 2006 8 2.25564
80 1-Sep-06 2006 9 1.10294
80 1-Oct-06 2006 10 1.90909
80 1-Nov-06 2006 11 2.05174
80 1-Dec-06 2006 12 1.07457
80 1-Jan-07 2007 1 0.97345
80 1-Feb-07 2007 2 0.35057
3 REPLIES 3
novinosrin
Tourmaline | Level 20

Hi @doylejm   By any chances are you asking for this?

 



data have;
input ID	date :date9.	year	month	ret;
format date date9.;
cards;
49	1-Nov-05	2005	11	2.65188
49	1-Dec-05	2005	12	0.0682
49	1-Jan-06	2006	1	0.4771
49	1-Feb-06	2006	2	0.90218
49	1-Mar-06	2006	3	0.97459
49	1-Apr-06	2006	4	0.42076
49	1-May-06	2006	5	-2.65363
49	1-Jun-06	2006	6	-0.46042
49	1-Jul-06	2006	7	0.2505
49	1-Aug-06	2006	8	2.3988
49	1-Sep-06	2006	9	2.42167
49	1-Oct-06	2006	10	2.24773
49	1-Nov-06	2006	11	0.98223
49	1-Dec-06	2006	12	0.81832
80	1-Jan-06	2006	1	3.29777
80	1-Feb-06	2006	2	-0.37559
80	1-Mar-06	2006	3	0.94251
80	1-Apr-06	2006	4	1.12045
80	1-May-06	2006	5	-2.67775
80	1-Jun-06	2006	6	0.09488
80	1-Jul-06	2006	7	0.85308
80	1-Aug-06	2006	8	2.25564
80	1-Sep-06	2006	9	1.10294
80	1-Oct-06	2006	10	1.90909
80	1-Nov-06	2006	11	2.05174
80	1-Dec-06	2006	12	1.07457
80	1-Jan-07	2007	1	0.97345
80	1-Feb-07	2007	2	0.35057
;


proc sql;
create table want as
select *
from have
group by id ,year
having n(month)=12 
order by id, date;
quit;
novinosrin
Tourmaline | Level 20

Hello @doylejm  Can you please mark as answered and close the thread when you can?Thank you!

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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
  • 3 replies
  • 484 views
  • 0 likes
  • 2 in conversation