BookmarkSubscribeRSS Feed
5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Do you simply want to generate a new variable or is there more to the question?

feige
SAS Employee

Use the following sample code:

proc sql;
select col1 into :var1 separated by ',' from lib1.table1;
quit;

if handle multiple columns into multiple variables, you can input the below code:

proc sql;
select col1,col2 into :var1, :var2
from table1;
quit;

Maybe you could look up SAS Documentation helper and find the appropriate answers.

Tom
Super User Tom
Super User

@feige wrote:

Use the following sample code:

proc sql;
select col1 into :var1 separated by ',' from lib1.table1;
quit;

if handle multiple columns into multiple variables, you can input the below code:

proc sql;
select col1,col2 into :var1, :var2
from table1;
quit;

Maybe you could look up SAS Documentation helper and find the appropriate answers.


That is not generating any variables.  The first one will populate a MACRO VARIABLE.  The second one will fail because the list of values to select goes BEFORE the INTO and the list of target macro variable names goes AFTER the INTO.

ballardw
Super User

Generic:

Proc Sql;
   create table wanted table as
   select <expression> as variablename
   from <some sort of source expression like a data set goes here>
  ;
quit;

Expressions could be just about any manipulation of one or more variables.

Sajid01
Meteorite | Level 14

The following code generate a new variable  BMI using SAS Proc SQL

proc sql;
select name, age ,height, weight ,703*weight/(height**2) as BMI format z5.2 
from sashelp.class;
quit;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1434 views
  • 0 likes
  • 6 in conversation