BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
pink_poodle
Barite | Level 11

Did anyone ever try to make music with SAS?

1 ACCEPTED SOLUTION

Accepted Solutions
manishiiita
Quartz | Level 8

Hi @pink_poodle, I didn't try it so far. In fact, after seeing your question I started exploring it.

 

It's interesting to know that you can make music in SAS. There are functions in SAS using which you can call any frequency (musical notes). You can define the duration as well for which you want to play any note.

 

All musical  notes are based on two primary parameters: Frequency & Duration. The CALL SOUND routine generates a sound with a specific frequency and duration using the following syntax:

CALL SOUND(frequency,duration);

Required arguments:

1. frequency – specifies the sound frequency in terms of cycles per second.  The frequency must be at least 20 and no greater than 20,000.
2. duration – specifies the sound duration in milliseconds.  The default is -1.

Example:


The following statement will play “middle C” for 2 seconds:
data _null_;
  call sound(261.63,2000);
run;  

 

Hope this will be helpful. You can refer to below document for more detailed understanding on this:

 

https://support.sas.com/resources/papers/proceedings16/3442-2016.pdf

View solution in original post

14 REPLIES 14
manishiiita
Quartz | Level 8

Hi @pink_poodle, I didn't try it so far. In fact, after seeing your question I started exploring it.

 

It's interesting to know that you can make music in SAS. There are functions in SAS using which you can call any frequency (musical notes). You can define the duration as well for which you want to play any note.

 

All musical  notes are based on two primary parameters: Frequency & Duration. The CALL SOUND routine generates a sound with a specific frequency and duration using the following syntax:

CALL SOUND(frequency,duration);

Required arguments:

1. frequency – specifies the sound frequency in terms of cycles per second.  The frequency must be at least 20 and no greater than 20,000.
2. duration – specifies the sound duration in milliseconds.  The default is -1.

Example:


The following statement will play “middle C” for 2 seconds:
data _null_;
  call sound(261.63,2000);
run;  

 

Hope this will be helpful. You can refer to below document for more detailed understanding on this:

 

https://support.sas.com/resources/papers/proceedings16/3442-2016.pdf

ChrisHemedinger
Community Manager

Here's another example, featuring a theme you might have heard before.

 

 

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
ballardw
Super User

I used to use the Call Sound to play a warning warble in some programs when I had a really critical issue.

 

But the current work environment I have all the speakers turned off so have quit playing with that.

Reeza
Super User

Almost that time of year and a blast from the past.

 

Here's the SAS Christmas Carol:

 

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));

 

One source is here:
https://groups.google.com/forum/#!topic/comp.soft-sys.sas/a9lmYmTNlv8

Though this is significantly older than that. You can always search on LexJansen.com to see some other variants. 

https://lexjansen.com/search/searchresults.php?q=music

pink_poodle
Barite | Level 11
This is great!
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

that is really cool.

 

SASKiwi
PROC Star

This will only work if you have Base SAS installed on a local PC / laptop. It wont work if you use Enterprise Guide or SAS Studio with a remote SAS server. 

pink_poodle
Barite | Level 11
I listened to the Christmas carol in SAS EG.
Reeza
Super User
Or SAS UE sadly 😞
Reeza
Super User
The thought of a random machine starting to
'sing' christmas carols in a data center does amuse me 🙂
pink_poodle
Barite | Level 11
A choir of machines for Christmas would be fun :).
BeverlyBrown
Community Manager

I love this thread! Wish I'd seen it earlier, @pink_poodle. Here's an example of SAS making music -- literally making charts and graphs "sing" through the SAS Graphics Accelerator. @EdSummers_SAS' team developed it to give visually impaired folks a way to "see" data  through sound.

 

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
pink_poodle
Barite | Level 11

Thank you, @BeverlyBrown! I think that representing mathematical functions with music is fascinating. It helps people and also quickens their understanding. Moreover, some functions sound nice and, in reverse, some music looks beautiful. James Huneker in his essay about Chopin's Ballades mentions an anecdote about Chopin and Meyerbeer. Meyerbeer quarreled with Chopin over a rhythm of a mazurka and said "Can one reduce women to notation? They would breed mischief were they emancipated from the measure." I wonder what that mazurka would look like as a graph. Most probably nothing like George Sand :). Makes one think of Cypher from the Matrix when he looked at the code, which, I recently found out, was sushi recipes from a Japanese cookbook of the producer's wife. 

BeverlyBrown
Community Manager

Love your observations! That Meyerbeer quote is priceless. Don't think it's coincidental that many software developers are also musicians. One of our execs told Forbes a while back that he always asks candidates about their hobbies. If the candidate mentions playing a musical instrument, that's a plus.

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 14 replies
  • 3994 views
  • 18 likes
  • 8 in conversation