Help using Base SAS procedures

Proper Calendar in SAS?

Reply
Occasional Contributor
Posts: 7

Proper Calendar in SAS?

Hi all,

I have been trying to create a calendar-style report - when I've seen examples using proc calendar, the output is very 80s like, using only ANSI characters.  But there must be a way to create a calendar report with a properly formatted grid and more up-to-date style, right?  I've found code that just creates the calendar, but don't know how to incorporate the dataset into this, as I am still pretty new to SAS:

Data Calendar;

Array Days(7) Sun Mon Tue Wed Thu Fri Sat (7*.);
Format Sun Mon Tue Wed Thu Fri Sat Date Date5.;
  Drop Date X;

Do Date = '01Jan2013'D to '31Mar2013'D by 1;
   Days(WeekDay(Date)) = Date;
   /*Quarter = Put(Date,YYQ6.);*/

   If WeekDay(Date) = 7 Then
   Do; Output;
    Do X=1 to Dim(Days); Days(X)=.; End;
   End;
  If Month(Date) NE Month(Date+1)Then
   Do; Output;
   Do X=1 to Dim(Days); Days(X)=.; End;
   End;
End;

If NMiss(Sun,Mon,Tue,Wed,Thu,Fri,Sat) < 7 Then Output;
Proc Print;
Title1 'Calendar Data Step Output';
Run;

This displays what's in the attachment.  Would I be able to do this using PROC Tabulate (or similar) and use NOOBS to hide the observation numbers?


calendar example.jpg
Super User
Posts: 10,046

Re: Proper Calendar in SAS?

You don't need other proc.

proc print has an option to suppress obs column.

proc print data=sashelp.class noobs;

run;

Ksharp

Super User
Super User
Posts: 7,078

Re: Proper Calendar in SAS?

There are a lot of functions to generate month, qtr, date, dow etc from an actual date value.

Try playing with this to see if you can make PROC REPORT create a nice calendar.

proc format ;

value dayname

   1='Sunday'

   2='Monday'

   3='Tuesday'

   4='Wednesday'

   5='Thursday'

   6='Friday'

   7='Saturday'

  ;

run;

data calendar ;

  do date= '01JAN2013'd to '31DEC2013'D ;

     year= year(date);

     qtr = qtr(date);

     month = month(date);

     day = day(date);

     week = week(date);

     dow = weekday(date);

     monname=put(date,monname.);

     downame=put(date,downame.);

     output;

  end;

run;

proc report nofs ;

  column year qtr month monname week dow,day ;

  define year / group order=internal noprint ;

  define qtr  / group order=internal noprint ;

  define month / group order=internal noprint ;

  define monname / group order=internal noprint ;

  define week / group order=internal noprint ;

  define dow  / across order=internal format=dayname. ' ';

  define day  / ' ';

  compute before monname ;

     x=length(monname);

     line @1 monname $varying20. x ' ' year 4. ;

  endcomp ;

  break after qtr / page;

run;

Respected Advisor
Posts: 3,799

Re: Proper Calendar in SAS?

I like @Tom's calander program.  I wondered if it could be done with aliases and formats.  I got close.  I had to make diplicates of DATE for some and could not figure how to make across work with a  formatted value of date.

If only the Across header could be repeated at the break on month.

proc format ;
   value dayname
     
1='Sunday'
     
2='Monday'
     
3='Tuesday'
     
4='Wednesday'
     
5='Thursday'
     
6='Friday'
     
7='Saturday'
      ;
   run;
data calendar ;
   do date= '01JAN2013'd to '31DEC2013'D ;
      qtr = date;
      monname=date;
      dow = weekday(date);
     
output;
     
end;
  
run;
options missing=' ';
proc report nofs list; * showall;
  
column date=year qtr date=month monname date=week dow,date=day;
   define year    / group order=internal noprint format=year.;
  
define qtr     / group order=internal noprint format=qtr.;
  
define month   / group order=internal noprint format=month.;
  
define monname / group order=internal noprint format=monname.;
  
define week    / group order=internal noprint format=weeku3.;
  
define dow     / across order=internal format=dayname9. ' ';
  
define day     / ' ' format=day.;
  
compute before monname ;
      line @1 monname monname. +1 year year.;
     
endcomp ;
   break after qtr / page;
  
run;
options missing='.';
Occasional Contributor
Posts: 7

Re: Proper Calendar in SAS?

Posted in reply to data_null__

Hi Tom and Data Null,

These are really great.  The one thing is, if I have a dataset that I can join by date, how can I plunk some data into these calendars along with the date number?  Is this a quick and easy thing or is it better to transpose the data itself and try to fit it into a calendar?

Thanks a bunch guys,

Tarun

Ask a Question
Discussion stats
  • 4 replies
  • 488 views
  • 4 likes
  • 4 in conversation