DATA Step, Macro, Functions and more

Extracting a variables by date

Reply
Occasional Contributor
Posts: 10

Extracting a variables by date

Hi 

I am trying to extract variables  from a dataset by certain date, but my code is not working. I will get the columns header with 0 rows.

can someone please help? attached is the code I use.

 

PROC SQL;
CREATE TABLE TEST AS
SELECT CURRENT_DATE, BLANK_NUMBER
FROM BLANK.DATA
WHERE CURRENT_DATE IN (04-01-2016 - 04-30-2016);
QUIT;

 

Thanks,

 

Super User
Posts: 10,483

Re: Extracting a variables by date

You should have gotten error messages with that code. In the future if you have code throwing errors include the log with the code and the error messages for best results.

 

If your current_date is an actual SAS date value then you do comparisons with literal values using "ddMONYYYY"D syntax. That is the only allowable form for explicit dates. So you likely needed to use "01APR2016"d and "30APR2016"d. Second the IN operator doesn't use a - to indicate a range, use : instead   in( 1:10) is range of 1 to 10.

 

Easier in this case may be to use

 

Where Month(Current_date) = 4

or

where Current_date is between "01APR2016"d and "30APR2016"d;

Occasional Contributor
Posts: 10

Re: Extracting a variables by date

Thanks ballardw! I try it but it did not work.

Super User
Posts: 10,483

Re: Extracting a variables by date

Please show the Log of the submitted code and any error messages. "Didn't work" is awful vague to try to work with.

Ask a Question
Discussion stats
  • 3 replies
  • 214 views
  • 0 likes
  • 2 in conversation