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

I am trying to find the number of participants between specific time period. How would be able to calculate that in SAS. For example,  How can determine the total number of hospital visitors from 10/20/2018 - until "today" who has positive flu test  from the table below? Please help! Thank you!

ID

date

Flu_test

1

2/8/2019

negative

2

6/12/2021

positive

3

7/10/2017

positive

4

6/23/2020

.

5

8/15/2019

positive

6

8/24/2017

negative

7

12/20/2020

positive

 

the outcome will be

3 = positive

1 = negative 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

If your date is an actual SAS date value then you can use a WHERE clause to identify records after a specific date by:

 

Where date > "20OCT2018"d;

The literal date must be in a Date9. (or date7. or other format with DDMONYY) in quotes and followed by the letter d to tell SAS you intend the value to be treated as a date.

 

Note the data step to create actual data that can be used with code. Please do so for future examples and paste into a text box opened with the </>  (shown) or the "running man" icon that appears above the message window.

data have;
   input ID $ date :mmddyy10. Flu_test $;
   format date mmddyy10.;
datalines;
1 2/8/2019 negative
2 6/12/2021 positive
3 7/10/2017 positive
4 6/23/2020 .
5 8/15/2019 positive
6 8/24/2017 negative
7 12/20/2020 positive
;


proc freq data=have;
   Where date > "20OCT2018"d; 
   tables flu_test;
run;

If your variable Date is not numeric with a date format applied that will be the first step: get a date value.

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Please post your data in usable form (instructions)

--
Paige Miller
ballardw
Super User

If your date is an actual SAS date value then you can use a WHERE clause to identify records after a specific date by:

 

Where date > "20OCT2018"d;

The literal date must be in a Date9. (or date7. or other format with DDMONYY) in quotes and followed by the letter d to tell SAS you intend the value to be treated as a date.

 

Note the data step to create actual data that can be used with code. Please do so for future examples and paste into a text box opened with the </>  (shown) or the "running man" icon that appears above the message window.

data have;
   input ID $ date :mmddyy10. Flu_test $;
   format date mmddyy10.;
datalines;
1 2/8/2019 negative
2 6/12/2021 positive
3 7/10/2017 positive
4 6/23/2020 .
5 8/15/2019 positive
6 8/24/2017 negative
7 12/20/2020 positive
;


proc freq data=have;
   Where date > "20OCT2018"d; 
   tables flu_test;
run;

If your variable Date is not numeric with a date format applied that will be the first step: get a date value.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 586 views
  • 1 like
  • 3 in conversation