Help using Base SAS procedures

Counting number of observations in a period

Accepted Solution Solved
Reply
Contributor
Posts: 35
Accepted Solution

Counting number of observations in a period

Hi guys,

I currently have data such as this:

DATE          CODE

196507      01384

196507      34098

196507      56565

196508      34354

196508      34353

196508      57098

I'm trying to count the number of observations within a month. So I should get

DATE       COUNT

196507       3

196508       3

.

Thanks a lot guys!

.

.

.

.


Accepted Solutions
Solution
‎02-13-2013 07:06 AM
Frequent Contributor
Posts: 81

Re: Counting number of observations in a period

Hi Benn,

Please find attached the code for the same:-

data raw;

input date code ;

datalines;

196507 01384

196507 34098

196507 56565

196508 34354

196508 34353

196508 57098

;

run;

proc sql;

create table cnt as select date,count(code) as count from raw group by date;

run;

proc print data=cnt;

run;

/Daman

View solution in original post


All Replies
Solution
‎02-13-2013 07:06 AM
Frequent Contributor
Posts: 81

Re: Counting number of observations in a period

Hi Benn,

Please find attached the code for the same:-

data raw;

input date code ;

datalines;

196507 01384

196507 34098

196507 56565

196508 34354

196508 34353

196508 57098

;

run;

proc sql;

create table cnt as select date,count(code) as count from raw group by date;

run;

proc print data=cnt;

run;

/Daman

Trusted Advisor
Posts: 1,129

Re: Counting number of observations in a period

we can get the same result in base sas

data test;

    input DATE          CODE;

cards;

196507      01384

196507      34098

196507      56565

196508      34354

196508      34353

196508      57098

;

run;

proc sort data=test;

    by date;

run;

data want;

    set test;

    retain count;

    by date;

    if first.date then count=1;

    else count+1;

    if last.date then output want;

run;

Thanks,

Jagadish

Thanks,
Jag
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 138 views
  • 3 likes
  • 3 in conversation