Do you simply want to generate a new variable or is there more to the question?
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.
@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.
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.
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;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.