Hello
I have read that sql is a declarative language.
Can anyone send an example why sql is a declarative language?
Is SAS also a declarative language?
Can anyone explain IF SAS is a procedural language?
Thanks
SQL is considered declarative, because you tell the computer what you want, not what to do.
E.g.:
create table x as select * from sashelp.class where sex='F' order by age,weight;
A very simple example, but basically, you do not tell the computer whether it should extract the data and sort afterwards, or sort first and then extract the records. I assume it does the first, but with more complicated examples there can be many ways to do things.
By SAS I suppose you mean SAS datastep language and base SAS procedures (excluding SQL).
The same thing as above can be accomplished with SORT and datastep in more than one way:
data x;
set sashelp class;
if sex='F';
run;
proc sort;
by age weight;
run;
or
proc sort data=sashelp.class out=temp;
by age weight;
run;
data x;
set temp;
if sex='F';
run;
The first method extracts first, and then sorts. The other does it the other way round.
You could also just use
proc sort data=sashelp.class out=x;
where sex='F';
by age weight;
run;
which does exactly what I expect SQL to implement in this simple example, but here the instructions are implicit:
Note that it is the use of the WHERE statement which defines that things are executed this way round, not the fact that the WHERE statement comes before the BY statement.
You can also do it the other way round with just PROC SORT:
proc sort data=sashelp.class out=x(where=(sex='F'));
by age weight;
run;
Here, the WHERE clause is on the output, meaning that we tell SAS to sort first and select afterwards.
The point is that in all these cases, we defined very clearly (although you have to have some experience to tell the difference) what was going to happen, and in what order. That's procedural. With SQL, we basically told what we wanted, and let the SQL interpreter decide how to do it. That's declarative.
Of course, there are degrees of declarativeness, especially when it comes to the procedures. With PROC SORT, we could have used options to tell SAS what kind of algorithm to use (e.g. TAGSORT, or invoking SYNCSORT, if we had that on our installation), but we chose not to, meaning that SAS will default to standard SAS sort (which may be changed or upgraded once in a rare while, or perhaps our installation has SYNCSORT set as default, meaning that that would be used).
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.