0

I want to filter date column for a table

data = sas.sasdata("METEOGROUP", "ABC", "PANDAS", 
               {
                   "where": 
                   "DATE_DAY>'2021-04-20'"
               }
              ).to_df()

But there is no result from this query. Without where clause i can see this dates. How can i solve this problem?

DATE_DAY continues dates like this ; 2016-05-03

Sevval Kahraman
  • 1,185
  • 3
  • 10
  • 37
  • 2
    The string '2021-04-20' is not a date. Dates are stored as numbers not strings. Did you try using a date constant instead of string? '20APR2021'd – Tom Mar 22 '23 at 12:09

1 Answers1

0

In SAS, dates are filtered using what is called a date literal. It is of the form 'DDMMMYYYY'd. For example, '01JAN2022'd. This automatically converts the string date into a SAS date, which is the number of days since Jan 1st 1960.

Here's an example of filtering sashelp.air to dates > March 1st 1955 and converting it into a pandas dataframe:

import pandas as pd
import saspy

sas = saspy.SASsession()

data = sas.sasdata('air', 'sashelp', 'pandas', {'where': "date > '01MAR1955'd"}).to_df()

data.head()
        DATE    AIR
0 1955-04-01  269.0
1 1955-05-01  270.0
2 1955-06-01  315.0
3 1955-07-01  364.0
4 1955-08-01  347.0
Stu Sztukowski
  • 10,597
  • 1
  • 12
  • 21