Can an SQL query select variables into different tables witn an INTO clause?

Viewed 36

I'm working myself through this guide to how to convert several character variables at once to numeric using SAS. The guide uses PROC SQL, the SQL interface of SAS. What got me wondering is the part following the INTO-clause below:

proc sql noprint; select trim(left(name)), trim(left(newname)),
trim(left(newname))||'='||trim(left(name))
into :c_list separated by ' ', :n_list separated by ' ',
:renam_list separated by ' '
from vars;

Essentially, the clause seems to select each variable into a different table. Are you allowed to do this in SQL, or is this only a feature of PROC SQL in SAS?

I tried the syntax at several SQL sandboxes, but couldn't get it to work.

2 Answers

It is a feature of PROC SQL in SAS to read values into SAS Macro Variables.

AFAIK there is no method to create multiple tables with a single query in SAS or ANSI SQL.

However, this is trivial within a SAS data step using a variety of methods.

The most basic:

   data male female;
      set sashelp.class;
      if sex='M' then output male;
      else if sex='F' then output female;
    run;
Related