BookmarkSubscribeRSS Feed
Tarun
Calcite | Level 5

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
4 REPLIES 4
Ksharp
Super User

You don't need other proc.

proc print has an option to suppress obs column.

proc print data=sashelp.class noobs;

run;

Ksharp

Tom
Super User Tom
Super User

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;

data_null__
Jade | Level 19

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='.';
Tarun
Calcite | Level 5

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 1487 views
  • 4 likes
  • 4 in conversation