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

Hi everyone,

 

New to SAS here... I'm trying to calculate the frequencies of variables between two different dates, and eventually looking to model this data.

 

I have tried:

Proc freq data=  intervention_dataset;

table var1 var 2 var 3 var 4;

where complete_d between '03/17/2020' and '08/20/2020'

run;

 

My complete_d variable is the date an assessment was completed, and I am looking to run this twice for two different dates. The column with the date the assessment was completed is formatted as MM/DD/YYYY. Do you think I need to change the date format in order to make this work? Currently I am only getting an error that says "WHERE clause operator requires compatible variables. 

 

Thank you!!

1 ACCEPTED SOLUTION

Accepted Solutions
sbxkoenk
SAS Super FREQ
Proc freq data=intervention_dataset;
 tables var1 var2 var3 var4;
*where complete_d between '03/17/2020' and '08/20/2020';
 where complete_d between '17MAR2020'd and '20AUG2020'd;
run;
/* end of program */

Koen

View solution in original post

3 REPLIES 3
sbxkoenk
SAS Super FREQ
Proc freq data=intervention_dataset;
 tables var1 var2 var3 var4;
*where complete_d between '03/17/2020' and '08/20/2020';
 where complete_d between '17MAR2020'd and '20AUG2020'd;
run;
/* end of program */

Koen

jiantos
Fluorite | Level 6

Thank you for your assistance, it is greatly appreciated. What an awesome community of support.

ballardw
Super User

" Currently I am only getting an error that says "WHERE clause operator requires compatible variables. :

That means the when you compare values that types must be the same. Since you are using

where complete_d between '03/17/2020' and '08/20/2020';

There are pretty much only two values:  your variable Complete_d and the strings you attempt to compare the value to. '03/17/2020' is a character value. So that is what generates the error.

DATE values stored in SAS are numeric number of days from a base day. As such, just like every other comparison, SAS uses the value of the variable for =, <, > or not equal comparisons. Because humans have created so many different, and sometimes quite confusing ways to indicate a specific "date" the syntax for SAS to specify a date is to use something in the form 'DDMONYYYY'd. The D after the string tells SAS you are attempting to use a date. None of the other formats. Quick if you see 01/02/03 what date does that represent? National rules come into that interpretation. I have seen people use such for 02 Jan 2003 (or 1903 back before 2000), 01 Feb 2003 (1903), or 2001(1901) Feb 03. So to make code consistent regardless of who rights it the folks at SAS decided "pick one that is easy to read": 'DDMonYYYY'd

The FORMAT does not have any affect on the comparison, ever, unless you specifically force a conversion of the value with the format such as put(somevar,thatformat.) = 'some result string'. Valid code.

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 534 views
  • 3 likes
  • 3 in conversation