Anda di halaman 1dari 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;

Anda mungkin juga menyukai