PROC SQL;
SELECT ID, MonYY AS MONTH, COUNT(ID) AS INVITEES
FROM TABLENAME
GROUP BY ID;
QUIT;
Proc SQL actually does provide a native approach for this problem, however, I got lost in your code and I am not sure how it works. it seems to me it would need more work like this:
data have;
infile cards;
input id $ InviteDate :ddmmyy10.;
format invitedate date9.;
cards;
1 01/01/2010
1 12/01/2010
1 15/05/2010
2 01/01/2010
2 15/05/2010
2 19/06/2010
2 30/07/2010
;
proc sql;
create table want as
select id, put(invitedate, monyy5.) as my, count(*) as ct
from have
group by id, calculated my
;quit;
proc print;run;
Regards,
Haikuo
When I ran your code the results are as follows.
Obs id my ct
1 1 JAN10 2
2 1 MAY10 1
3 2 JAN10 1
4 2 JUL10 1
5 2 JUN10 1
6 2 MAY10 1
Here are the results from my code
Obs id my ct
1 1 JAN10 2
2 1 MAY10 1
3 2 JAN10 1
4 2 JUL10 1
5 2 JUN10 1
6 2 MAY10 1
I dont see anything different in the results.
What is your platform? Are you using SAS? I am running SAS 9.2 on winxp sp3 32bit. Your code does not work on my machine, and it seems to me it does not have valid syntax. Please try again or provide your full running code.
Hello -
I realize that you might not have access to SAS/ETS software - however, in case you do, you might want to consider running PROC TIMESERIES (which creates some nice summary stats as well - see OUTSUM data set) - after modifying your source data slightly.
If you don't care about month a person was not contacted, simply get rid of the setmissing option.
Regards,
Udo
data have;
infile cards;
input id $ InviteDate :ddmmyy10. ct;
format invitedate date9.;
cards;
1 01/01/2010 1
1 12/01/2010 1
1 15/05/2010 1
2 01/01/2010 1
2 15/05/2010 1
2 19/06/2010 1
2 30/07/2010 1
;
proc timeseries data=have out=want outsum=outsum;
id invitedate interval=month accumulate=total setmissing=0;
var ct;
by id;
run;
Good catch Mr.Hai.kuo. Not sure how I overlooked at it. Please ignore my previous code. This should work fine now.
Code:
PROC SQL;
CREATE TABLE HAVE1 AS
SELECT ID, invitedate AS MONTH FORMAT MMYYS., COUNT(ID) AS INVITEES
FROM have
QUIT;
PROC FREQ DATA = HAVE1;
TABLES ID * MONTH /LIST MISSING NOROW NOCOL NOPERCENT NOCUM;
RUN;
Output:
The FREQ Procedure
id MONTH Frequency
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
1 01/2010 2
1 05/2010 1
2 01/2010 1
2 05/2010 1
2 06/2010 1
2 07/2010 1
LOG:
628 PROC SQL;
629 CREATE TABLE HAVE1 AS
630 SELECT ID, invitedate AS MONTH FORMAT MMYYS., COUNT(ID) AS INVITEES
631 FROM have
632 QUIT;
NOTE: The query requires remerging summary statistics back with the original data.
NOTE: Table WORK.HAVE1 created, with 7 rows and 3 columns.
633
NOTE: PROCEDURE SQL used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
634 PROC FREQ DATA = HAVE1;
635 TABLES ID * MONTH /LIST MISSING NOROW NOCOL NOPERCENT NOCUM;
636 RUN;
NOTE: There were 7 observations read from the data set WORK.HAVE1.
NOTE: PROCEDURE FREQ used (Total process time):
real time 0.03 seconds
cpu time 0.01 seconds
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.