个人技术分享

SAS SQL

语法

proc sql;
	select columns
	from table
	where columns
	group by columns
;
quit;

SQL查询在proc sql语句之后,加上quit语句,用于结束SQL查询

SQL CREATE

data example;
	input id $ name $ studynum;
	datalines;
		1 Maria 2024168001
		2 Michelle 2024168002
		3 Lucy 2024168003
		4 Gary 2024168004
	;
run;

proc sql;
	create table temp as
	select * from example
;
quit;

SQL SELECT

proc sql;
	select name,height,weight
	from sashelp.class
;
quit;

SQL SELECT with WHERE Clause

proc sql;
	select name,height,weight
	from sashelp.class
	where height > 60
;
quit;

SQL UPDATE

proc sql;
	create table class as
	select  name as student,
			sex as gender,
			age as year,
			height as stuheight,
			weight as stuweight,
			weight/((height/100)*(height/100)) as bmi
	from sashelp.class;
quit;
proc sql;
	update class
	set stuheight=stuheight/100;
quit;

SQL DELETE

proc sql;
	delete from class
	where weight<60;
quit;