We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

How do i group date variables in SAS Output?

shandayani
shandayani asked
on
Medium Priority
669 Views
Last Modified: 2012-06-21
I am working with a table that holds data on patient visits. There is a "Visit Date" column and the dates contained in it span over 6 years (Thousands of records).

I want to run a frequency distribution on the entire table but this gives me countless lines of output due to the variability of the dates.

What I am trying to do is to use PROC FORMAT to group the date output into 3 months each so that i can better read my data. Please is there a way this can be done?
Comment
Watch Question

SharathData Engineer
CERTIFIED EXPERT

Commented:
try grouping on Year and Quarter.
SELECT YEAR(VisitDate) AS Year_VisitDate, 
         QTR(VisitDate)  AS Qtr_VisitDate, 
         COUNT(* ) 
    FROM your_table 
GROUP BY YEAR(VisitDate), 
         QTR(VisitDate)

Open in new window

Author

Commented:
Thanks for you reply.
I did forget to mention that I am using SAS though. Will this still work?
I have never used SELECT statements with in SAS.
SharathData Engineer
CERTIFIED EXPERT

Commented:
It should. give a try.
IanStatistician
CERTIFIED EXPERT

Commented:
What is needed is

PROC SQL;

    SELECT YEAY(VisitDate)  AS Year_VisitDate,
 
...   As above ...
...  End with a semicolon ...
        ;

QUIT;

check out the documentation for. PROC. SQL.  it's syntax is very different to other PROCS.  However it is very useful.

Ian
IanStatistician
CERTIFIED EXPERT

Commented:
Or you can just SASstandard formats,

PROC FREQ data=your_data order=formatted;

      FORMAT VisitDate. YYQC6.0;

      TABLES  VisitDate;

RUN;

_____________

This ,applies a format of   yyyy:q    To the date variable and the order=formatted. Makes it use this formatted value for the summary, instead of the full formatted date.

Ian
Statistician
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.