Libanme certadv ‘/folders/myfolders/certadv;
proc sql;
create table work.result as
select month, date, case
when RevCargo < 2000 then 'low'
when RevCargo < 24000 then 'middle'
else 'high'
end as new_var3
from certadv.cargorev;
quit;
4. 写一个array,把一个dataset的所有的missing value变成0-
Libname cert ‘/folders/myfolders/cert/input’; .
Data miss; . Χ
Set cert.input04;
Array vars(*) _numeric_;
Do i=1 to dim(vars);
If vars(i)=. then vars(i)=0;
End;
Drop I;
Run; .
Proc print; . 1point3acres.com
Run; . check 1point3acres for more.
5. 写一个array,把var12-var15所有的missing value变0
Libname cert ‘/folders/myfolders/cert/input’;
Data miss;
Set cert.input004;
Array vars(4) var12-var15;/注意:array的名字Vars不能和变量的名字重复,变量名字是var没有s
Do i=1 to 4
If vars(i)=. then vars(i)=0;/注意:这里是Array的名字 ..
End; . From 1point 3acres bbs
Drop I;
Run;
Proc print; ..
Run; .1point3acres
6. proc fcmp IN to CM, 建好function后options cmplib=work.functions,然后建个新data里面有个新列newheight=IN to CM(height)cm=2.45IN
libname certadv ‘/folders/myfolders/certadv’; .1point3acres
proc fcmp outlib=work.function.add; . 1point 3acres
function add(inch);
cm=inch*2.45;
return(cm); .--endsub;
run;
options cmplib=work.function; .google и
data work.height; ..
set certadv.all;
Height=add(fee);
Run;
Proc print data=work.Height;
Run;
7. array 把q1-q10的A,B,C,D,E换成1,2,3,4,5存在num1-num10中
. check 1point3acres for more.
proc import datafile=’/folders/myfolders/certadv/ABCDE.xlsx’
dbms=xlsx
out=abcde
replace;
run; . From 1point 3acres bbs这里跑一次
data work.result;
SET abcde;
Drop i;
ARRAY qq (10) Q1-Q10;
ARRAY numnum (10) num1-num10;
DO i=1 to 10;
If qq(i)=’A’ then numnum(i)=1;
Else If qq(i)=’B’ then numnum(i)=2; . .и
Else If qq(i)=’C’ then numnum(i)=3;
Else If qq(i)=’D’ then numnum(i)=4;
Else If qq(i)=’E’ then numnum(i)=5; . 1point3acres
End; ..
Run;
这里再跑第二次
proc sql;
select avg(RevCargo)
into: mvar
from certadv.cargorev
where Date=20160;
.
考试里是Where region='AMR' ; (注意:where 不是when )
quit;
11. use SQL to create a new table that contains all unique values of Make and Type from cert.cars, and Rebate from cert.rebate. For Rebate, show Make and Type if matching; if no matching Make and Type, show missing. Only three variable: Make, Type, Rebate.
Proc sql;
Create table cert.car as
Select cars.make, cars.type, rebate.rebate
From cert.cars full join cert.rebate
On cars.make=rebate.make and on cars.type=rebate.type
Quit;
. 12. Hash form: 根据country19建立hash表,然后input contry20,根据key查表,成功的输出work.XXX, 失败的输出到work.errors。
length Country name $30;
if _n_=1 then do;
call missing(Country name);
declare hash C(dataset:'country19');
C.definekey('country_code');
C.definedata('country_name');
C.definedone(); . 1point3acres
end;
set country20; .--
rc=c.find( );
if rc=0 then output info19;
else output errors19;
run;
自己练习书本课后题:
Data work.success work.fail;
Drop rc;
Length Ctname $30; . 1point 3acres
If _N_=1 then do;
Call missing (Ctname);
Declare hash c(dataset:’certadv.continent’);
c.definekey(‘ID’);
c.definedata(‘Ctname’)
c.definedone();
end;
set certadv.airports;
rc=c.find();
if rc=0 then output work.success;
else output work.fail;
run;