BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sogauli6
Calcite | Level 5
To get a date range with ‘if’ statement . I only need to select 1981 year date there is 6 date with that year.
Data a;
Set Sonu. Emp;
If hiredate >= ‘20feb1981’d and <= ‘03dec1981’d;
Run;
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You forgot the second hiredate

 

Data a;
Set Sonu. Emp;
If hiredate >= '20feb1981'd and  hiredate <= '03dec1981'd;
Run;

 But you can also use the YEAR function:

Data a;
Set Sonu. Emp;
If year(hiredate) = 1981;
Run;

and for ranges you can use something like this as well:

Data a;
Set Sonu. Emp;
If  '20feb1981'd <= hiredate <= '03dec1981'd;
Run;

@sogauli6 wrote:
To get a date range with ‘if’ statement . I only need to select 1981 year date there is 6 date with that year.
Data a;
Set Sonu. Emp;
If hiredate >= ‘20feb1981’d and <= ‘03dec1981’d;
Run;

EDIT: you also have curly quotes not straight ones (you copied and pasted from somewhere?). Those will likely cause an issue with your code and I've updated this post to fix those. 

View solution in original post

2 REPLIES 2
Reeza
Super User

You forgot the second hiredate

 

Data a;
Set Sonu. Emp;
If hiredate >= '20feb1981'd and  hiredate <= '03dec1981'd;
Run;

 But you can also use the YEAR function:

Data a;
Set Sonu. Emp;
If year(hiredate) = 1981;
Run;

and for ranges you can use something like this as well:

Data a;
Set Sonu. Emp;
If  '20feb1981'd <= hiredate <= '03dec1981'd;
Run;

@sogauli6 wrote:
To get a date range with ‘if’ statement . I only need to select 1981 year date there is 6 date with that year.
Data a;
Set Sonu. Emp;
If hiredate >= ‘20feb1981’d and <= ‘03dec1981’d;
Run;

EDIT: you also have curly quotes not straight ones (you copied and pasted from somewhere?). Those will likely cause an issue with your code and I've updated this post to fix those. 

sogauli6
Calcite | Level 5
Thank you

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 756 views
  • 1 like
  • 2 in conversation