Did anyone ever try to make music with SAS?
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
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
Here's another example, featuring a theme you might have heard before.
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.
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(¬e,1,=));
%let duration = %scan(¬e,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.
that is really cool.
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.
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.
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.
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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.