Working with date

Accepted Solution Solved
Reply
Super Contributor
Posts: 328
Accepted Solution

Working with date

[ Edited ]

Hello-,

 

I am trying to create a variable year from SAS date.  

 

When I run this code on the date, I get the wrong answer:


data want1;

input Birthdate;
cards;

 

 
5/27/2014
5/28/2014
5/29/2014
5/30/2014
5/31/2014
6/1/2014
6/2/2014
6/3/2014
6/4/2014
6/5/2014
6/6/2014
6/7/2014
6/8/2014
6/9/2014
6/10/2014
6/11/2014
6/12/2014
6/13/2014
6/14/2014
6/15/2014
6/16/2014
6/17/2014
6/18/2014
6/19/2014
6/20/2014
6/21/2014
6/22/2014
6/23/2014
6/24/2014
6/25/2014
6/26/2014
6/27/2014
6/28/2014
6/29/2014
6/30/2014
7/1/2014
7/2/2014
7/3/2014
7/4/2014
7/5/2014
7/6/2014
7/7/2014
7/8/2014
7/9/2014
7/10/2014
7/11/2014
7/12/2014
7/13/2014
7/14/2014
7/15/2014
7/16/2014
7/17/2014
7/18/2014
7/19/2014
7/20/2014
7/21/2014
7/22/2014
7/23/2014
7/24/2014
7/25/2014
7/26/2014
7/27/2014
7/28/2014
7/29/2014
7/30/2014
7/31/2014
8/1/2014
8/2/2014
8/3/2014
8/4/2014
8/5/2014
8/6/2014
8/7/2014
8/8/2014
8/9/2014
8/10/2014
8/11/2014
8/12/2014
8/13/2014
8/14/2014
8/15/2014
8/16/2014
8/17/2014
8/18/2014
8/19/2014
8/20/2014
8/21/2014
8/22/2014
8/23/2014
8/24/2014
8/25/2014
8/26/2014
8/27/2014
8/28/2014
8/29/2014
8/30/2014
8/31/2014
9/1/2014
9/2/2014
9/3/2014
9/4/2014
9/5/2014
9/6/2014
9/7/2014
9/8/2014
9/9/2014
9/10/2014
9/11/2014
9/12/2014
9/13/2014
9/14/2014
9/15/2014
9/16/2014
9/17/2014
9/18/2014
9/19/2014
9/20/2014
9/21/2014
9/22/2014
9/23/2014
9/24/2014
9/25/2014
9/26/2014
9/27/2014
9/28/2014
9/29/2014
9/30/2014
10/1/2014
10/2/2014
10/3/2014
10/4/2014
10/5/2014
10/6/2014
10/7/2014
10/8/2014
10/9/2014
10/10/2014
10/11/2014
10/12/2014
10/13/2014
10/14/2014
10/15/2014
10/16/2014
10/17/2014
10/18/2014
10/19/2014
10/20/2014
10/21/2014
10/22/2014
10/23/2014
10/24/2014
10/25/2014
10/26/2014
10/27/2014
10/28/2014
10/29/2014
10/30/2014
10/31/2014
11/1/2014
11/2/2014
11/3/2014
11/4/2014
11/5/2014
11/6/2014
11/7/2014
11/8/2014
11/9/2014
11/10/2014
11/11/2014
11/12/2014
11/13/2014
11/14/2014
11/15/2014
11/16/2014
11/17/2014
11/18/2014
11/19/2014
11/20/2014
11/21/2014
11/22/2014
11/23/2014
11/24/2014
11/25/2014
11/26/2014
11/27/2014
11/28/2014
11/29/2014
11/30/2014
12/1/2014
12/2/2014
12/3/2014
12/4/2014
12/5/2014
12/6/2014
12/7/2014
12/8/2014
12/9/2014
12/10/2014
12/11/2014
12/12/2014
12/13/2014
12/14/2014
12/15/2014
12/16/2014
12/17/2014
12/18/2014
12/19/2014
12/20/2014
12/21/2014
12/22/2014
12/23/2014
12/24/2014
12/25/2014
12/26/2014
12/27/2014
12/28/2014
12/29/2014
12/30/2014
12/31/2014
1/1/2015
1/2/2015
1/3/2015
1/4/2015
1/5/2015
1/6/2015
1/7/2015
1/8/2015
1/9/2015
1/10/2015
1/11/2015
1/12/2015
1/13/2015
1/14/2015
1/15/2015
1/16/2015
1/17/2015
1/18/2015
1/19/2015
1/20/2015
1/21/2015
1/22/2015
1/23/2015
1/24/2015
1/25/2015
1/26/2015
1/27/2015
1/28/2015
1/29/2015
1/30/2015
1/31/2015
2/1/2015
2/2/2015
2/3/2015
2/4/2015
2/5/2015
2/6/2015
2/7/2015
2/8/2015
2/9/2015
2/10/2015
2/11/2015
2/12/2015
2/13/2015
2/14/2015
2/15/2015
2/16/2015
2/17/2015
2/18/2015
2/19/2015
2/20/2015
2/21/2015
2/22/2015
2/23/2015
2/24/2015
2/25/2015
2/26/2015
2/27/2015
2/28/2015
3/1/2015
3/2/2015
3/3/2015
3/4/2015
3/5/2015
3/6/2015
3/7/2015
3/8/2015
3/9/2015
3/10/2015
3/11/2015
3/12/2015
3/13/2015
3/14/2015
3/15/2015
3/16/2015
3/17/2015
3/18/2015
3/19/2015
3/20/2015
3/21/2015
3/22/2015
3/23/2015
3/24/2015
3/25/2015
3/26/2015
3/27/2015
3/28/2015
3/29/2015
3/30/2015
3/31/2015
4/1/2015
4/2/2015
4/3/2015
4/4/2015
4/5/2015
4/6/2015
4/7/2015
4/8/2015
4/9/2015
4/10/2015
4/11/2015
4/12/2015
4/13/2015
4/14/2015
4/15/2015
4/16/2015
4/17/2015
4/18/2015
4/19/2015
4/20/2015
4/21/2015
4/22/2015
4/23/2015
4/24/2015
4/25/2015
4/26/2015
4/27/2015
4/28/2015
4/29/2015
4/30/2015
5/1/2015
5/2/2015
5/3/2015
5/4/2015
5/5/2015
5/6/2015
5/7/2015
5/8/2015
5/9/2015
5/10/2015
5/11/2015
5/12/2015
5/13/2015
5/14/2015
5/15/2015
5/16/2015
5/17/2015
5/18/2015
5/19/2015
5/20/2015
5/21/2015
5/22/2015
5/23/2015
5/24/2015
5/25/2015
5/26/2015
5/27/2015
5/28/2015
5/29/2015
5/30/2015
5/31/2015
6/1/2015
6/2/2015
6/3/2015
6/4/2015
6/5/2015
6/6/2015
6/7/2015
6/8/2015
6/9/2015
6/10/2015
6/11/2015
6/12/2015
6/13/2015
6/14/2015
6/15/2015
6/16/2015
6/17/2015
6/18/2015
6/19/2015
6/20/2015
6/21/2015
6/22/2015
6/23/2015
6/24/2015
6/25/2015
6/26/2015
6/27/2015
6/28/2015
6/29/2015
6/30/2015
7/1/2015
7/2/2015
7/3/2015
7/4/2015
7/5/2015
7/6/2015
7/7/2015
7/8/2015
7/9/2015
7/10/2015
7/11/2015
7/12/2015
7/13/2015
7/14/2015
7/15/2015
7/16/2015
7/17/2015
7/18/2015
7/19/2015
7/20/2015
7/21/2015
7/22/2015
7/23/2015
7/24/2015
7/25/2015
7/26/2015
7/27/2015
7/28/2015
7/29/2015
7/30/2015
7/31/2015
8/1/2015
8/2/2015
8/3/2015
8/4/2015
8/5/2015
8/6/2015
8/7/2015
8/8/2015
8/9/2015
8/10/2015
8/11/2015
8/12/2015
8/13/2015
8/14/2015
8/15/2015
8/16/2015
8/17/2015
8/18/2015
8/19/2015
8/20/2015
8/21/2015
8/22/2015
8/23/2015
8/24/2015
8/25/2015
8/26/2015
8/27/2015
8/28/2015
8/29/2015
8/30/2015
8/31/2015
9/1/2015
9/2/2015
9/3/2015
9/4/2015
9/5/2015
9/6/2015
9/7/2015
9/8/2015
9/9/2015
9/10/2015
9/11/2015
9/12/2015
9/13/2015
9/14/2015
9/15/2015
9/16/2015
9/17/2015
9/18/2015
9/19/2015
9/20/2015
9/21/2015
9/22/2015
9/23/2015
9/24/2015
9/25/2015
9/26/2015
9/27/2015
9/28/2015
9/29/2015
9/30/2015
10/1/2015
10/2/2015
10/3/2015
10/4/2015
10/5/2015
10/6/2015
10/7/2015
10/8/2015
10/9/2015
10/10/2015
10/11/2015
10/12/2015
10/13/2015
10/14/2015
10/15/2015
10/16/2015
10/17/2015
10/18/2015
10/19/2015
10/20/2015
10/21/2015
10/22/2015
10/23/2015
10/24/2015
10/25/2015
10/26/2015
10/27/2015
10/28/2015
10/29/2015
10/30/2015
10/31/2015
11/1/2015
11/2/2015
11/3/2015
11/4/2015
11/5/2015
11/6/2015
11/7/2015
11/8/2015
11/9/2015
11/10/2015
11/11/2015
11/12/2015
11/13/2015
11/14/2015
11/15/2015
11/16/2015
11/17/2015
11/18/2015
11/19/2015
11/20/2015
11/21/2015
11/22/2015
11/23/2015
11/24/2015
11/25/2015
11/26/2015
11/27/2015
11/28/2015
11/29/2015
11/30/2015
12/1/2015
12/2/2015
12/3/2015
12/4/2015
12/5/2015
12/6/2015
12/7/2015
12/8/2015
12/9/2015
12/10/2015
12/11/2015
12/12/2015
12/13/2015
12/14/2015
12/15/2015
12/16/2015
12/17/2015
12/18/2015
12/19/2015
12/20/2015
12/21/2015
12/22/2015
12/23/2015
12/24/2015
12/25/2015
12/26/2015
12/27/2015
12/28/2015
12/29/2015
12/30/2015
12/31/2015
1/1/2016
1/2/2016
1/3/2016
1/4/2016
1/5/2016
1/6/2016
1/7/2016
1/8/2016
1/9/2016
1/10/2016
1/11/2016
1/12/2016
1/13/2016
1/14/2016
1/15/2016
1/16/2016
1/17/2016
1/18/2016
1/19/2016
1/20/2016
1/21/2016
1/22/2016
1/23/2016
1/24/2016
1/25/2016
1/26/2016
1/27/2016
1/28/2016
1/29/2016
1/30/2016
1/31/2016
2/1/2016
2/2/2016
2/3/2016
2/4/2016
2/5/2016
2/6/2016
2/7/2016
2/8/2016
2/9/2016
2/10/2016
2/11/2016
2/12/2016
2/13/2016
2/14/2016
2/15/2016
2/16/2016
2/17/2016
2/18/2016
2/19/2016
2/20/2016
2/21/2016
2/22/2016
2/23/2016
2/24/2016
2/25/2016
2/26/2016
2/27/2016
2/28/2016
2/29/2016
3/1/2016
3/2/2016
3/3/2016
3/4/2016
3/5/2016
3/6/2016
3/7/2016
3/8/2016
3/9/2016
3/10/2016
3/11/2016
3/12/2016
3/13/2016
3/14/2016
3/15/2016
3/16/2016
3/17/2016
3/18/2016
3/19/2016
3/20/2016
3/21/2016
3/22/2016
3/23/2016
3/24/2016
3/25/2016
3/26/2016
3/27/2016
3/28/2016
3/29/2016
3/30/2016
3/31/2016
4/1/2016
4/2/2016
4/3/2016
4/4/2016
4/5/2016
4/6/2016
4/7/2016
4/8/2016
4/9/2016
4/10/2016
4/11/2016
4/12/2016
4/13/2016
4/14/2016
4/15/2016
4/16/2016
4/17/2016
4/18/2016
4/19/2016
4/20/2016
4/21/2016
4/22/2016
4/23/2016
4/24/2016
4/25/2016
4/26/2016
4/27/2016
4/28/2016
4/29/2016
4/30/2016
5/1/2016
5/2/2016
5/3/2016
5/4/2016
5/5/2016
5/6/2016
5/7/2016
5/8/2016
5/9/2016
5/10/2016
5/11/2016
5/12/2016
5/13/2016
5/14/2016
5/15/2016
5/16/2016
5/17/2016
5/18/2016
5/19/2016
5/20/2016
5/21/2016
5/22/2016
5/23/2016
5/24/2016
5/25/2016
5/26/2016
5/27/2016
5/28/2016
5/29/2016
5/30/2016
5/31/2016
6/1/2016
6/2/2016
6/3/2016
6/4/2016
6/5/2016
6/6/2016
6/7/2016
6/8/2016
6/9/2016
6/10/2016
6/11/2016
6/12/2016
6/13/2016
6/14/2016
6/15/2016
6/16/2016
6/17/2016
6/18/2016
6/19/2016
6/20/2016
6/21/2016
6/22/2016
6/23/2016
6/24/2016
6/25/2016
6/26/2016
6/27/2016
6/28/2016
6/29/2016
6/30/2016
7/1/2016
7/2/2016
7/3/2016
7/4/2016
7/5/2016
7/6/2016
7/7/2016
7/8/2016
7/9/2016
7/10/2016
7/11/2016
7/12/2016
7/13/2016
7/14/2016
7/15/2016
7/16/2016
7/17/2016
7/18/2016
7/19/2016
7/20/2016
7/21/2016
7/22/2016
7/23/2016
7/24/2016
7/25/2016
7/26/2016
7/27/2016
7/28/2016
7/29/2016
7/30/2016
7/31/2016
8/1/2016
8/2/2016
8/3/2016
8/4/2016
8/5/2016
8/6/2016
8/7/2016
8/8/2016
8/9/2016
8/10/2016
8/11/2016
8/12/2016
8/13/2016
8/14/2016
8/15/2016
8/16/2016
8/17/2016
8/18/2016
8/19/2016
8/20/2016
8/21/2016
8/22/2016
8/23/2016
8/24/2016
8/25/2016
8/26/2016
8/27/2016
8/28/2016
8/29/2016
8/30/2016
8/31/2016
9/1/2016
9/2/2016
9/3/2016
9/4/2016
9/5/2016
9/6/2016
9/7/2016
9/8/2016
9/9/2016
9/10/2016
9/11/2016
9/12/2016
9/13/2016
9/14/2016
9/15/2016
9/16/2016
9/17/2016
9/18/2016
9/19/2016
9/20/2016
9/21/2016
9/22/2016
9/23/2016
9/24/2016
9/25/2016
9/26/2016
9/27/2016
9/28/2016
9/29/2016
9/30/2016
10/1/2016
10/2/2016
10/3/2016
10/4/2016
10/5/2016
10/6/2016
10/7/2016
10/8/2016
10/9/2016
10/10/2016
10/11/2016
10/12/2016
10/13/2016
10/14/2016
10/15/2016
10/16/2016
10/17/2016
10/18/2016
10/19/2016
10/20/2016
10/21/2016
10/22/2016
10/23/2016
10/24/2016
10/25/2016
10/26/2016
10/27/2016
10/28/2016
10/29/2016
10/30/2016
10/31/2016
11/1/2016
11/2/2016
11/3/2016
11/4/2016
11/5/2016
11/6/2016
11/7/2016
11/8/2016
11/9/2016
11/10/2016
11/11/2016
11/12/2016
11/13/2016
11/14/2016
11/15/2016
11/16/2016
11/17/2016
11/18/2016
11/19/2016
11/20/2016
11/21/2016
11/22/2016
11/23/2016
11/24/2016
11/25/2016
11/26/2016
11/27/2016
11/28/2016
11/29/2016
11/30/2016
12/1/2016
12/2/2016
12/3/2016
12/4/2016
12/5/2016
12/6/2016
12/7/2016
12/8/2016
12/9/2016
12/10/2016
12/11/2016
12/12/2016
12/13/2016
12/14/2016
12/15/2016
12/16/2016
12/17/2016
12/18/2016
12/19/2016
12/20/2016
12/21/2016
12/22/2016
12/23/2016
12/24/2016
12/25/2016
12/26/2016
12/27/2016
12/28/2016
12/29/2016
12/30/2016
12/31/2016
1/1/2017
1/2/2017
1/3/2017
1/4/2017
1/5/2017
1/6/2017
1/7/2017
1/8/2017
1/9/2017
1/10/2017
1/11/2017
1/12/2017
1/13/2017
1/14/2017
1/15/2017
1/16/2017
1/17/2017
1/18/2017
1/19/2017
1/20/2017
1/21/2017
1/22/2017
1/23/2017
1/24/2017
1/25/2017
1/26/2017
1/27/2017
1/28/2017
1/29/2017
1/30/2017
1/31/2017
2/1/2017
2/2/2017
2/3/2017
2/4/2017
2/5/2017
2/6/2017
2/7/2017
2/8/2017
2/9/2017
2/10/2017
2/11/2017
2/12/2017
2/13/2017
2/14/2017
2/15/2017
2/16/2017
2/17/2017
2/18/2017
2/19/2017
2/20/2017
2/21/2017
2/22/2017
2/23/2017
2/24/2017
2/25/2017
2/26/2017
2/27/2017
2/28/2017
3/1/2017
3/2/2017
3/3/2017
3/4/2017
3/5/2017
3/6/2017
3/7/2017
3/8/2017
3/9/2017
3/10/2017
3/11/2017
3/12/2017
3/13/2017
3/14/2017
3/15/2017
3/16/2017
3/17/2017
3/18/2017
3/19/2017
3/20/2017
3/21/2017
3/22/2017
3/23/2017
3/24/2017
3/25/2017
3/26/2017
3/27/2017
3/28/2017
3/29/2017
3/30/2017
3/31/2017
4/1/2017
4/2/2017
4/3/2017
4/4/2017
4/5/2017
4/6/2017
4/7/2017
4/8/2017
4/9/2017
4/10/2017
4/11/2017
4/12/2017
4/13/2017
4/14/2017
4/15/2017
4/16/2017
4/17/2017
4/18/2017
4/19/2017
4/20/2017
4/21/2017
4/22/2017
4/23/2017
4/24/2017
4/25/2017
4/26/2017
4/27/2017
4/28/2017
4/29/2017
4/30/2017
5/1/2017
5/2/2017
5/3/2017
5/4/2017
5/5/2017
5/6/2017
5/7/2017
5/8/2017
5/9/2017
5/10/2017
5/11/2017
5/12/2017
5/13/2017
5/14/2017
5/15/2017
5/16/2017
5/17/2017
5/18/2017
5/19/2017
5/20/2017
5/21/2017
5/22/2017
5/23/2017
5/24/2017
5/25/2017
5/26/2017
5/27/2017
5/28/2017
5/29/2017
5/30/2017
5/31/2017
6/1/2017
6/2/2017
6/3/2017
6/4/2017
6/5/2017
6/6/2017
6/7/2017
6/8/2017
6/9/2017
6/10/2017
6/11/2017
6/12/2017
6/13/2017
6/14/2017
6/15/2017
6/16/2017
6/17/2017
6/18/2017
6/19/2017
6/20/2017
6/21/2017
6/22/2017
6/23/2017
6/24/2017
6/25/2017
6/26/2017
6/27/2017
6/28/2017
6/29/2017
6/30/2017
7/1/2017
7/2/2017
7/3/2017
7/4/2017
7/5/2017
7/6/2017
7/7/2017
7/8/2017
7/9/2017
7/10/2017
7/11/2017
7/12/2017
7/13/2017
7/14/2017
7/15/2017
7/16/2017
7/17/2017
7/18/2017
7/19/2017
7/20/2017
7/21/2017
7/22/2017
7/23/2017
7/24/2017
7/25/2017
7/26/2017
7/27/2017
7/28/2017
7/29/2017
7/30/2017
7/31/2017
8/1/2017
8/2/2017
8/3/2017
8/4/2017
8/5/2017
8/6/2017
8/7/2017
8/8/2017
8/9/2017
8/10/2017
8/11/2017
8/12/2017
8/13/2017
8/14/2017
8/15/2017
8/16/2017
8/17/2017
8/18/2017
8/19/2017
8/20/2017
8/21/2017
8/22/2017
8/23/2017
8/24/2017
8/25/2017
8/26/2017
8/27/2017
8/28/2017
8/29/2017
8/30/2017
8/31/2017
9/1/2017
9/2/2017
9/3/2017
9/4/2017
9/5/2017
9/6/2017
9/7/2017
9/8/2017
9/9/2017
9/10/2017
9/11/2017
9/12/2017
9/13/2017
9/14/2017
9/15/2017
9/16/2017
9/17/2017
9/18/2017
9/19/2017
9/20/2017
9/21/2017
9/22/2017
9/23/2017
9/24/2017
9/25/2017
9/26/2017
9/27/2017
9/28/2017
9/29/2017
9/30/2017
10/1/2017
10/2/2017
10/3/2017
10/4/2017
10/5/2017
10/6/2017
10/7/2017
10/8/2017
10/9/2017
10/10/2017
10/11/2017
10/12/2017
10/13/2017
10/14/2017
10/15/2017
10/16/2017
10/17/2017
10/18/2017
10/19/2017
10/20/2017
10/21/2017
10/22/2017
10/23/2017
10/24/2017
10/25/2017
10/26/2017
10/27/2017
10/28/2017
10/29/2017
10/30/2017
10/31/2017
11/1/2017
11/2/2017
11/3/2017
11/4/2017
11/5/2017
11/6/2017
11/7/2017
11/8/2017
11/9/2017
11/10/2017
11/11/2017
11/12/2017
11/13/2017
11/14/2017
11/15/2017
11/16/2017
11/17/2017
11/18/2017
11/19/2017
11/20/2017
11/21/2017
11/22/2017
11/23/2017
11/24/2017
11/25/2017
11/26/2017
11/27/2017

;

run;
if 05/27/2014<=BirthDate<05/27/2015 then year=1;
else if 05/27/2015<=BirthDate<05/27/2016 then year=2;
else if 05/27/2016<=BirthDate<05/27/2017 then year=3;
else if BirthDate>=05/27/2017 then year=4;
run;

 

proc freq data=want1;
table year;
run;

 

Wrong results:

 

SAS Output

year Frequency Percent Cumulative
Frequency
Cumulative
Percent
4 20207 100.00 20207 100.00

 

data:

 

 

 

SAS Output

 

Accepted Solutions
Solution
‎05-09-2018 12:57 AM
PROC Star
Posts: 1,765

Re: Working with date

Posted in reply to desireatem

first you didnt read corretly with input statement like

 

input birthdate :mmddyy10.;

 

a

nd then you need sas date constants like this

if '27may/2014'd<=BirthDate<'27may2015'd then year=1;

View solution in original post


All Replies
Solution
‎05-09-2018 12:57 AM
PROC Star
Posts: 1,765

Re: Working with date

Posted in reply to desireatem

first you didnt read corretly with input statement like

 

input birthdate :mmddyy10.;

 

a

nd then you need sas date constants like this

if '27may/2014'd<=BirthDate<'27may2015'd then year=1;

☑ This topic is solved.

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

Discussion stats
  • 1 reply
  • 146 views
  • 1 like
  • 2 in conversation