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

Hello,

I am looking for information on how to use a WHERE statement in a PROC PRINT to specify a date. For example I want to show all observations where data equal to 1 Jan 2000.

Regards,

P.

1 ACCEPTED SOLUTION

Accepted Solutions
AncaTilea
Pyrite | Level 9

hi,

proc print data = your_data;

     where date = mdy(01,01,2000);

var var_list;

run;

Best of luck,

Anca.

View solution in original post

9 REPLIES 9
AncaTilea
Pyrite | Level 9

hi,

proc print data = your_data;

     where date = mdy(01,01,2000);

var var_list;

run;

Best of luck,

Anca.

pmdci
Fluorite | Level 6

Hi Anca,

Thanks for that. Is it possible to use the same function to return all observations from January 2000, regardless of the day?

Regards,

P.

Linlin
Lapis Lazuli | Level 10

print data=have;

where date between mdy(1,1,2000) and mdy(1,31,2000);

run;

Linlin
Lapis Lazuli | Level 10

or:

data have;

input date mmddyy10.;

format date mmddyy10.;

cards;

01/31/2000

01/02/2000

02/04/2000

;

proc print data=have;

where date between intnx('month','01jan2000'd,0,'b') and intnx('month','01jan2000'd,0,'e') ;

run;

Reeza
Super User

where date = '01jan2000'd;

Notice the d at the end and the quotations around the date. The quotations can be single or double and the year can be two or four digit.

pmdci
Fluorite | Level 6

Hi Reeza,

What is the d at the end for? Also how would SAS know the date format (e.g.: dd/mm/yy, mm/dd/yy, dd/mm/yyyy, etc) and would it be possible to specify only the month and the year?

Regards,

P.

Reeza
Super User

SAS stores dates as numbers, the format is only used to display the numbers so when you specify the 'd' it tells SAS it's a date and it converts it into a number.

You can also specify a between with the literals:

where date between '01jan2000'd and '31jan2000'd but then you have to know the start and end of the month. 

LinLin's solution above is better for that.

You could also specify the month and year separately

where month(date)=1 and year(date)=2000;

RichardinOz
Quartz | Level 8

@pmdci

The SAS date literal requires the date to be in a DATE informat.  Other date informats are not supported. The following will work (not an exhaustive list):

     '01jan80'd

     '01jan1980'd

     '01-jan-1980'd

You could use the INTCK function :

print data=have;

     where intck('month', '1jan2000'd, date) = 0 ;

run;


Richard

Haikuo
Onyx | Level 15

As you can see, SAS is very resourceful when dealing with date variable, the following two options should work for you as well:

where month(date)=1 and year(date)=2000;

where put(date,monyy7.)='JAN2000';

Haikuo

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 9 replies
  • 986 views
  • 6 likes
  • 6 in conversation