BookmarkSubscribeRSS Feed
mmea
Quartz | Level 8

Hi. If i have a dataset looking like this 

DateEvent
01JAN2020event1
01JAN2020event1
01JAN2020event1
02JAN2020.
02JAN2020.

Is it possible to make a new dataset that has a column that counts the same combinations? Like this:

Dateeventcount
01JAN2020event13
02JAN2020.2
10 REPLIES 10
PaigeMiller
Diamond | Level 26
proc freq data=have;
    tables date*event/missing noprint out=_counts_;
run;
data want;
    merge have _counts_;
    by date event;
run;

This assumes the data set is sorted by DATE and EVENT.

--
Paige Miller
mmea
Quartz | Level 8

Thanks. i works.

Can i then put it in a proc sql an only get the distinct values.

Because now in my data the same combinations can appear multiple times

PaigeMiller
Diamond | Level 26

@mmea wrote:

 

Can i then put it in a proc sql an only get the distinct values.

Because now in my data the same combinations can appear multiple times


Doesn't PROC FREQ give you the distinct combinations of date and event? What do you mean by the above? Show us what you mean.

--
Paige Miller
novinosrin
Tourmaline | Level 20

Somebody who wants SQL solutions is likely my colleague either in RI, MA, CT or PA

 



data have;
input Date :date9.	Event $;
format date date9.;
cards;
01JAN2020	event1
01JAN2020	event1
01JAN2020	event1
02JAN2020	.
02JAN2020	.
;
proc sql;
 create table want as
 select date, event, count(*) as count
 from have
 group by date, event;
quit;
anming
Pyrite | Level 9

data have;
input Date date9. Event $;
format date date9.;
cards;
01JAN2020 event1
01JAN2020 event1
01JAN2020 event1
01JAN2020 event1
02JAN2020 .
02JAN2020 .
;
run;

proc freq data=have ;
tables date/out=test1;
/* output _counts_; */
run;

data want1;
set test1 (drop=percent);
run;

data want2;
set have;
set want1;
run;

 

try this.

PaigeMiller
Diamond | Level 26

Can you actually type a data set that represents the desired output? I thought you did originally, my code produces that data set, but then you asked more questions and seemed to want something else.

 

So, it's still not clear what result you want, or why you have created the following data set using two SET statements. You have not explained, and I am asking you to please explain, provide details, more than the two words "try this", and SHOW us what you want if it is different than what you asked for in your first message. It's also not clear to me why you have removed the MISSING option from my TABLES statement in PROC FREQ, as I would think you want that based on your original explanation.

 

--
Paige Miller
ballardw
Super User

@PaigeMiller wrote:

Can you actually type a data set that represents the desired output? I thought you did originally, my code produces that data set, but then you asked more questions and seemed to want something else.

 

So, it's still not clear what result you want, or why you have created the following data set using two SET statements. You have not explained, and I am asking you to please explain, provide details, more than the two words "try this", and SHOW us what you want if it is different than what you asked for in your first message. It's also not clear to me why you have removed the MISSING option from my TABLES statement in PROC FREQ, as I would think you want that based on your original explanation.

 


@PaigeMiller 

I think you responded to @anming thinking that was the OP @mmea . I believe anming is proposing an alternate solution?

anming
Pyrite | Level 9

yes. I am trying to provide an alternative solution.

PaigeMiller
Diamond | Level 26

@anming wrote:

yes. I am trying to provide an alternative solution.


Alternative in what way? It doesn't appear to give the same answer as was requested in the original message.

--
Paige Miller
PaigeMiller
Diamond | Level 26

@ballardw wrote:

@PaigeMiller wrote:

Can you actually type a data set that represents the desired output? I thought you did originally, my code produces that data set, but then you asked more questions and seemed to want something else.

 

So, it's still not clear what result you want, or why you have created the following data set using two SET statements. You have not explained, and I am asking you to please explain, provide details, more than the two words "try this", and SHOW us what you want if it is different than what you asked for in your first message. It's also not clear to me why you have removed the MISSING option from my TABLES statement in PROC FREQ, as I would think you want that based on your original explanation.

 


@PaigeMiller 

I think your responded to @anming thinking that was the OP @mmea . I believe anming is proposing an alternate solution?


My apologies to @mmea for the mis-understanding.

--
Paige Miller

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 10 replies
  • 2835 views
  • 1 like
  • 5 in conversation