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;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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