Posts

Lesson 1: SQL as a calculator 1

# an example data null; y=.; PROC SQL;   SELECT 2+3, 11*3, 2**5, cos(constant("pi")/3), exp(-1/2), log(2)   FROM null   ; QUIT; # an alternative,   which I prefer PROC SQL  inobs =1;      SELECT 2+3, 11*3, 2**5, cos(constant("pi")/3), exp(-1/2), log(2)   FROM sashelp.cars   ; QUIT; Note: columns in SELECT should be separated by " , ".  Note: SQL needs a table after FROM. A dummy dataset "null" is created to feed it. PROC SQL  inobs =1;      SELECT 2+3, 11*3, 2**5, cos(constant("pi")/3), exp(-1/2), log(2)   FROM sashelp.cars   ; QUIT; ---------------------------------------------------------- 5 33 32 0.5 0.606531 0.693147    Note: Any SAS system has SASHELP library, in which there are lots of datasets including CARS. We can use it to feed FROM with inobs=1 to read just one line from the dataset. If you skip inobs=1, you will see the consequence. outobs=1 al

Introduction

This blog is for Statistician/SAS programmer who wants to replace data step with SQL for data manipulation. I have been shy away from writing a public positing in English because my mother language is not English. I may use this blog as my English Writing 101 class, so please correct my English brutally. I will really appreciate it. Why I use SQL over data step in SAS? 1. It provides me a joy of thinking. When I use data step, I tend to google a lot to find the similar situation. However, with SQL, I try to solve the problem by thinking a lot.  2. Data step seems to have been build up its functionality based on user's need. As a result, it is far from being structured. However, SQL is a language for database, which is better structured.  3. The codes created using SQL tend to be much shorter and more readable than the ones using data step. 4. Someday, your company may decide not to use SAS anymore or you may want a career change to be a data scientist. No problem! Yo