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

Hello Everyone , I have this Dataset:

regions cities Dates
1 FGG 25/01/1998
1 HGT 26/01/1998
1 HJK 27/01/1998
2 LOI .
2 DCF 25/01/2001
2 VG 26/01/2001
2 BBVB 28/01/2001
3 DFR 11/07/2005
3 ZAS 12/07/2005

 

And What I want to do is , to take the mean of the Dates , when I have multiple Dates for the same region , like my output would be something like this :

 

regions cities Dates
1 FGG 26/01/1998
1 HGT 26/01/1998
1 HJK 26/01/1998
2 LOI 26/01/2001
2 DCF 26/01/2001
2 VG 26/01/2001
2 BBVB 26/01/2001
3 DFR 11/07/2005
3 ZAS 11/07/2005
3 EWS 16/02/2010
3 WE 16/11/2010

 

 

Any Suggestion On how to do that would be much appreciated , thank you.

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20


data have;
input regions	cities $	Dates :ddmmyy10.;
format dates ddmmyy10.;
cards;
1	FGG	25/01/1998
1	HGT	26/01/1998
1	HJK	27/01/1998
2	LOI	.
2	DCF	25/01/2001
2	VG	26/01/2001
2	BBVB	28/01/2001
3	DFR	11/07/2005
3	ZAS	12/07/2005
;


proc sql;
create table want1 as
select regions, cities,mean(dates) as dates format=ddmmyy10.
from have
group by regions;
quit;

View solution in original post

6 REPLIES 6
novinosrin
Tourmaline | Level 20


data have;
input regions	cities $	Dates :ddmmyy10.;
format dates ddmmyy10.;
cards;
1	FGG	25/01/1998
1	HGT	26/01/1998
1	HJK	27/01/1998
2	LOI	.
2	DCF	25/01/2001
2	VG	26/01/2001
2	BBVB	28/01/2001
3	DFR	11/07/2005
3	ZAS	12/07/2005
;


proc sql;
create table want1 as
select regions, cities,mean(dates) as dates format=ddmmyy10.
from have
group by regions;
quit;
Midi
Obsidian | Level 7

Thank's a Lot.

ballardw
Super User

First thing, is your "date" and actual SAS date value? From what you show it should be a numeric variable with format of ddmmyy10. or similar.

 

If not then you need to get date values and we would need to see what you have to accomplish that.

Midi
Obsidian | Level 7

In my real Dataset my dates are in Date9. Format

PeterClemmensen
Tourmaline | Level 20

Your want data set has 2 obs more than your input? How does that happen?

PaigeMiller
Diamond | Level 26
proc summary data=have;
    class regions;
    var dates;   
    output out=_means_ mean=;
urn;
--
Paige Miller

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 6 replies
  • 524 views
  • 0 likes
  • 5 in conversation