0

For some reason I'm not being able to read in the data properly. I want to be able to read in a large data set but within only specific dates such as Jan 2004 to FEB 2004. My Code is the following:

DATA Work.sales_fact;
SET Work.sales_fact_subset;
WHERE '01JAN2004'd <= Order_Date <= '14FEB2004'd;
RUN;

PROC PRINT;
RUN;

What am I doing incorrectly?

  • You're missing an AND... WHERE '01JAN2004'd <= Order_Date AND Order_Date <= '14FEB2004'd; – RamB Feb 08 '16 at 19:49
  • Syntax looks fine to me. What makes you think something is wrong? Are you getting an error message? Returning the wrong number of records? Check that Order_Date is a numeric date variable. This step is reading sales_fact_subset. Do you mean to read sales_fact instead? – Quentin Feb 08 '16 at 19:53
  • It just doesnt seem to read in the data accordingly. I get the entire dataset instead of the subset from those dates im asking for. @ramb still doesnt work. – Konfu Chicken Feb 08 '16 at 20:01
  • You're right, I'm assamed I didnt know that this syntax would work. I'll leave an example as an answer using a SASHelp Dataset. – RamB Feb 08 '16 at 20:10
  • What values do you see for order_date from `proc means data=sales_fact_subset min mean max; var Order_Date; run;` ? And again, are you sure you intend to read sales_fact_subset or do you intend to read sales_fact? – Quentin Feb 08 '16 at 20:10
  • @Quentin, if you want, you can answer this with an example like mine and your suggestions. I'll then delete my answer if you do. – RamB Feb 08 '16 at 20:16
  • 1
    I'm going to guess that your date isn't actually a SAS date, if you're reading from a database such as SQL it's probably a datetime variable instead. – Reeza Feb 08 '16 at 20:16

3 Answers3

4

I think you have DATA and SET switched. DATA is what you want to create. SET is where the data is coming from.

DATA Work.sales_fact_subset ;
SET Work.sales_fact;
WHERE '01JAN2004'd <= Order_Date <= '14FEB2004'd;
RUN;

PROC PRINT data=Work.sales_fact_subset;
RUN;
DomPazz
  • 12,415
  • 17
  • 23
0

Here is an example of this working.. Please check your dataset.

data want;
set sashelp.rent;
where "01feb1999"d <= date <= "02feb2003"d;
run;
RamB
  • 428
  • 4
  • 11
0

If your table names and date structure is correct, your query is correct. Here is a sample of what I did with the correct result set.

 data inputs;
       input Date1 date9. ;
       Format date1 date9.;
       cards;
01JAN2004 
02FEB2004
03MAR2004
04JUN2004
05JUL2004 
    ;



DATA inputss;
SET inputs;
WHERE '01JAN2004'd <= Date1 <= '14FEB2004'd;
RUN;

PROC PRINT;
RUN;

enter image description here

Keneni
  • 705
  • 5
  • 12