BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Benn
Calcite | Level 5

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!

.

.

.

.

1 ACCEPTED SOLUTION

Accepted Solutions
damanaulakh88
Obsidian | Level 7

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

2 REPLIES 2
damanaulakh88
Obsidian | Level 7

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

Jagadishkatam
Amethyst | Level 16

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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