Link to home
Start Free TrialLog in
Avatar of shandayani
shandayani

asked on

How do i group date variables in SAS Output?

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?
Avatar of Sharath S
Sharath S
Flag of United States of America image

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

Avatar of shandayani
shandayani

ASKER

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.
It should. give a try.
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
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
ASKER CERTIFIED SOLUTION
Avatar of Ian
Ian
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial