where name in (select name in cert.XXXX)
.1point3acres 2. 在PROC SQL里面创建一个新的Variable,case expression:
.1point3acres
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 . 1point 3 acres
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); . 1point 3 acres
If vars(i)=. then vars(i)=0;
End; . check 1point3acres for more.
Drop I;
Run; .google иProc print;
Run;
. From 1point 3acres bbs 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;
Drop I;
Run;
Proc print;
Run; . 1point3acres
. 1point3acres.com 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’;
proc fcmp outlib=work.function.add;
function add(inch);
cm=inch*2.45; . check 1point3acres for more.
return(cm); .--
endsub;
run; . Waral dи,
options cmplib=work.function; . 1point3acres
data work.height;
set certadv.all;
Height=add(fee); ..
Run;
Proc print data=work.Height; . 1point3acresRun;
proc import datafile=’/folders/myfolders/certadv/ABCDE.xlsx’
dbms=xlsx
out=abcde
replace;
run; . 1point 3 acres
这里跑一次
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; . Waral dи,
Else If qq(i)=’D’ then numnum(i)=4;
Else If qq(i)=’E’ then numnum(i)=5;
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 .1point3acres
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;
. 1point 3 acres 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'); .1point3acres
C.definedone();
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;
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;
. 1point 3 acres
proc print data=work.success;
run;