100% found this document useful (1 vote)
38 views

The Semi Colon Is Used at The End of Proc SQL Statement

The document discusses various SQL statements and techniques used for data manipulation and analysis using PROC SQL in SAS, including: - Creating tables with PROC SQL and defining variable types and lengths. - Inserting data into tables using SET and VALUES options. - Common SELECT statements to pick variables, observations, unique values, and perform calculations. - Using functions like COUNT, SUM, and COALESCE to manipulate data. - Filtering data with WHERE and HAVING clauses. - Grouping and ordering data. - Different types of joins between tables.

Uploaded by

Nagesh Khandare
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
38 views

The Semi Colon Is Used at The End of Proc SQL Statement

The document discusses various SQL statements and techniques used for data manipulation and analysis using PROC SQL in SAS, including: - Creating tables with PROC SQL and defining variable types and lengths. - Inserting data into tables using SET and VALUES options. - Common SELECT statements to pick variables, observations, unique values, and perform calculations. - Using functions like COUNT, SUM, and COALESCE to manipulate data. - Filtering data with WHERE and HAVING clauses. - Grouping and ordering data. - Different types of joins between tables.

Uploaded by

Nagesh Khandare
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

*the semi colon is used at the end of proc sql statement, after quit and the statement before

quit...the variable mentioned as char, we have to mention the length of the variable; proc sql; create table emp (id num,name char(20), doj num informat date9. format ddmmyy !.); quit; *to feed the values in the variable, can be done by " types..set and values; *e#ample of set option; proc sql; insert into emp set id$101, name$%&eepi'a%,doj$"01Jan2009"d set id$102, name$%(mita%,doj$"05Mar2010"d; quit; *e#ample of values command; proc sql; insert into emp values(101,%&eepi'a%,"01Jan2009"d) values(102,%(urya%,"02Feb2008"d); quit; )))))))))))))))))))))))))))))))))))))))))) *data manipulation; *proc sql(sequence to be followed) select$ pic'ing variables from$ dataset name where$condition on every observation group by$grouping variable having$condition order by$for sorting quit; * astri' is used to pic' all the variables from the dataset; proc sql; select * from local.baseball; quit; *to select few variables from the dataset; proc sql; select model,type,country from local.cars; quit; *to pic' unique values in respect to a variable; proc sql; select distinct league

from local.baseball; quit; *to select unique variations in a dataset; proc sql; select distinct * from local.baseball; quit; *to select obs from a dataset; proc sql inobs$4 outobs$10; select * from local.cars; quit; *to use a function on a dataset; proc sql; select count(no*hits) as total*hits from local.baseball; quit; *too add this new variable in a new a table; proc sql; create table rajan as select *, min(no*hits) as total*hits from local.baseball; quit; *to perform calculation on the base of two variable; proc sql; select origin,dest,(capacity)deplaned) as diff format 10.,capacity,deplaned from flights; quit; proc sql; select (no*hits+sum(no*hits)) as percent format 5.2 from local.baseball; quit; *to show it terms of percentage; proc sql; select (no*hits+sum(no*hits)) as percent format percent,." from local.baseball; quit; *having is used for the variables where the calculation is done and an aggregation is done, e# sum..var..count...and for for order by, calculater command is not required; proc sql;

select (no*hits+sum(no*hits))*100 as percent format 5.2 from local.baseball having calculated percent-5; quit; *we can use and . or statements in the where conditions; proc sql; select origin,dest,(capacity)deplaned) as diff format 10.,capacity,deplaned from flights where calculated diff-19; quit; libname files %/01&ocuments and (ettings12cl1&es'top1files1files%; *to replace missing values with a value; proc sql; select name,coalesce(lowpoint,%34%) as lowpoint from files.continents; quit; *to replace a missing numeric value with a value defined using coalesce; proc sql; select name,coalesce(area,12334) as area from files.continents; quit; proc sql; create table cont as select *, coalesce(area,12334) as area from files.continents; quit; *to use if and else if commands, here we use case and when satements; *the comma after latitude defines that there is a variable to be ceated; *we are not ma'ing any changes in the data set and directly creating a report; proc sql; select city,latitude, case when latitude5)23 then %3orth 6rigid% when latitude between )23 and 23 then %7emperate% when latitude -23 then %(outh 6rigid% end as climate*8one from files.worldcitycoords; quit; *group by; proc sql; select category,sum(units) from local.candy*sales*summary group by category; quit; proc sql;

select dest, sum(capacity) from flights group by dest; quit; proc sql; select dest,sum(deplaned) from flights group by dest having deplaned-230; quit; proc sql; select category,units from local.candy*sales*summary where units-2000 order by category,units desc; quit; *joins+merge, the variable name can be different and sorting is not required, will create a report and not a data set; *only 9 types of joins; *e#act$inner join inner$full join left inner$left join right inner$right join; data set ; input order*no order*amt deliverydate; informat deliverydate date9.; format deliverydate ddmmyy.; datalines; ! "!!! !9jan"!!, "! ,!!! !feb"!!: ;!9 :!!! ,mar"!!< ; run; data set"; input /3= order*no >urchasequantity; datalines; 4 ?9 ! !!!! @"9,; 9, !!! 4;,:9 "! ,!! ; run; *e#ample of inner join; proc sql; select y.order*no,order*amt,purchasequantity from set as # right join set" as y on #.order*no$y.order*no;

quit;

You might also like