An off-topic spot to chat about your musings of the day

Holiday music in a SAS program

Reply
Community Manager
Posts: 2,644

Holiday music in a SAS program

[ Edited ]

It's that time of year again -- the time when the holiday season distracts us from our work and we try to find ways to put our SAS programs in the spirit of the season.

 

Have a copy of PC SAS?  Try running this program -- with your headphones in or PC speakers turned up.  The program has been floating around in SAS communities for years and I confess I don't know the original author.  I last saw it shared by @mlamias on SAS-L many years ago, but it was since referenced in this SAS Users blog post.

 

/* http://blogs.sas.com/content/sgf/fridays-innovation-inspiration-jingle-bells/ */
data holidays;
  retain fmtname '@$holiday';
  length data $3;
  ratio = 1.05946309436;
  str1 ='A A#B C C#D D#E F F#G G#';
  str2='A BbCbB#DbD EbFbE#GbG Ab';
  o = 1;
  do i = 0 to 87;
    p = 55 * ratio**i;
        data = compress(substr(str1,mod(i,12)*2+1,2)||o);
    output;
        if data^=compress(substr(str2,mod(i,12)*2+1,2)||o) then do;
          data = compress(substr(str2,mod(i,12)*2+1,2)||o);
          output;
        end;
        if mod(i,12)=2 then o=o+1;
  end;
  rename data=start p=label;
  keep fmtname data p;
run;
proc format cntlin=holidays; run;
%macro play(input);
data _Null_;
  %let i=1;
  %do %while(%scan(&input,&i,%str( ))^=);
    %let note = %scan(&input,&i,%str( ));
        %let pitch = %upcase(%scan(&note,1,=));
        %let duration = %scan(&note,2,=);
    %let i = %eval(&i+1);
        %if &pitch=R %then
          call sleep((1/&duration)*750);
        %else
          call sound(input("&pitch",$holiday.),(1/&duration)*300);
    ;
  %end;
run;
%mend;
%play(%str(
C6=1 B5=1.5 A5=6 G5=1 R=2 F5=2 E5=1 D5=1 C5=1
R=2 G5=2 A5=1 R=2 A5=2 B5=1 R=2 B5=2 C6=.33
C6=2 C6=2 B5=2 A5=2 G5=2 G5=1.5 F5=4 E5=2
C6=2 C6=2 B5=2 A5=2 G5=2 G5=1.5 F5=4 E5=2 E5=2
E5=2 E5=2 E5=2 E5=4 F5=4 G5=1 R=4 F5=4 E5=4
D5=2 D5=2 D5=2 D5=4 E5=4 F5=1 R=4 E5=4 D5=4
C5=2 C6=1 A5=2 G5=1.5 F5=6 E5=2 F5=2 E5=1 D5=1 C5=1 ));

For those without PC SAS, here is a recording for your enjoyment:

Regular Contributor
Posts: 212

Re: Holiday music in a SAS program

Hi Chris,

 

I've tried to genarate a sound but it didn't work in my SAS Enterprise Guide 5.1

 

What can i do to work ?

Community Manager
Posts: 2,644

Re: Holiday music in a SAS program

Sorry @DartibaliRodrigo, this type of program requires a local PC SAS on your Windows machine.  It won't work in SAS Enterprise Guide or SAS Studio (unless the SAS session is also running on a local Windows box). CALL SOUND works only on Windows.

 

I added a recording of the playback so you can enjoy...

This widget could not be displayed.
This widget could not be displayed.
Ask a Question
Discussion stats
  • 2 replies
  • 281 views
  • 1 like
  • 2 in conversation