2、寫一個含有comment的macro(comment的內容不能執行), 後面macro的內容是一個proc print的語句,最後執行這個macro
proc print data=certadv.lab9;proc print data=certadv.lab9;3、一個loop macro,輸入start和end,在循環中判斷i是否大於10,大於10開始data step
3、創建一個table,讀取某個文件的所有變量,但是只顯示另外一個文件裡NAME存在的觀測
create table sql01 as select * where name in (select name from x2);4、Having avg大於150 用department進行分組,按一個variable進行sort select age, avg(height) as AVG_H from sashelp.class having /*calculated*/ AVG_H>50 create table work.lab7 as select *, avg(salary) as avgsalary having /*calculated*/ avgsalary >= (select median(salary) fromcertadv.lab7);5、用sql把region='AMR'的avg(var)存成一個macro variable select avg(weight) into: avg_weight select avg(height) avg(weight) select distinct cars.make, cars.type, rebate.rebate from cert.cars leftjoin cert.rebate on cars.make=rebate.make and cars.type=rebate.type;6、從一個表中選 unique Make and Type,從另一個表中匹配Rebate,有對應的Make 和 Type 則顯示Rebate,否則為空。 select distinct cars.make, cars.type, rebate.rebate from cert.cars left join cert.rebate on cars.make=rebate.make and cars.type=rebate.type;7、在SQL裡面從cert.cargorev中創建一個new Variable: create table work.result as when 0<RevCargo<24000 then 'L' when 24000<=RevCargo<=52000 then 'M' create table new_table as when height >=180 then 'high' when height >=170 and height <180 then 'middle' when height <170 then'low' select avg(height) into: avghgt1、用array把inch單位的height變量轉換為cm單位的newheight array ls(*) LENGTH1-LENGTH3; array new(*)NEWLENGTH1-NEWLENGTH3; array inch[3] height1-height3; array cm[3] newheight1-newheight3; input Name$ N M P Q S T; array vars (*) _numeric_;/*用於不確定array的維度時,_numeric_指dataset中所有numeric的變量*/ do i = 1 to dim(vars);/* 用dim(vars)來確定循環的次數*/ if vars(i)=. then vars(i)= 0;3、寫一個array,把var12-var15所有的missing value變0 array vars(4) var12-var15; if vars(i)=. then vars(i)=0;4、用array 替換變量裡的A,B,C,D,E到1,2,3,4,5並輸出到新的array裡 input col1$ col2$ col3$ col4$ col5$ col6$ col7$ col8$ col9$ col10$ ; array newcol[10] newvar1-newvar10; if c(i)= 'A' then newcol(i)= 1; else if c(i)= 'B' then newcol(i)= 2; else if c(i)= 'C' then newcol(i)= 3; else if c(i)= 'D' then newcol(i)= 4; else if c(i)= 'E' then newcol(i)= 5;1、proc fcmp自定義函數INtoCM 將inch單位轉換為CM單位proc fcmp outlib=work.function.dev;options cmplib=work.function; NewHeight=INtoCM(height);proc fcmp outlib=work.function.dev;function inchtocm(height);options cmplib=work.function;newheight=inchtocm(height);/*Weightchange: lbs to kg 將lbs 轉換為kg */proc fcmp outlib=work.a.c;options cmplib=(work.functions);proc fcmp outlib=work.function.dev;function reversname(name $) $;newname = catx(" ", scan(name,2,","),scan(name,1,","));options cmplib=work.function;new_name =reversname(name);data work.success work.fail; drop rc; /*後面要用rc做查找,~drop i*/ length YYName $30; /*YYName 建立變量 */ if _N_=1 then do; /* 固定格式*/ call missing (YYName); /* call missing初始化YYName*/ declare hashC(dataset:'x1'); /* 聲明hash表,名字和dataset會給,記得單引號*/ c.definekey('ID'); /* 定義hash key,ID,key在題目裡,記得單引號*/ c.definedata('YYName'); /* 定義hash data ,YYNameLength */ c.definedone(); /* hash定義完的聲明,固定格式*/ set cert.planes; /* 用建立的hash表查找的另一個表,跟定義hash的表不同 */ rc=c.find(); /* 哈希表的查找結果,如果rc=0,就說明查找成功,這個cert.planes裡面有哈希表這樣一個對應關係, if rc=0 then output work.success; /* 如果rc=0,查找成功,那麼就輸出成功表 */ if rc ne 0 then output work.fail; /* 如果rc不等於0,查找失敗,那麼就輸出失敗表 */1、創建hash table,在另一個dataset裡面查找key,成功的話輸出
2、Hash 根據country19建立hash表,然後input contry20,根據key查表,成功的輸出work.XXX,失敗的輸出到work.errors
福利時刻
後臺回覆:ADV,即可獲取SAS ADV認證考試選擇題65+20題題庫和機經。
、