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.
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;
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;
Thank's a Lot.
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.
In my real Dataset my dates are in Date9. Format
Your want data set has 2 obs more than your input? How does that happen?
proc summary data=have;
class regions;
var dates;
output out=_means_ mean=;
urn;
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!
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.