where name in (select name in cert.XXXX)
. From 1point 3acres bbs 2. 在PROC SQL里面创建一个新的Variable,case expression:
Libanme certadv ‘/folders/myfolders/certadv;
proc sql;
create table work.result as
select month, date, case
when RevCargo < 2000 then 'low' .1point3acres
when RevCargo < 24000 then 'middle'
else 'high'
end as new_var3
from certadv.cargorev;
quit; . Waral dи,
3. 让你建一个maro,在do loop里面写一个if语句; -baidu 1point3acres
%macro loop(start,end);
%do i =&start %to &end;
%if &i>10 %then %do; .google и
data x&i;
x=&i; . From 1point 3acres bbs
run;
%end;
%end;
%mend;
%loop(1,200);
. check 1point3acres for more. 4. 写一个array,把一个dataset的所有的missing value变成0-
Libname cert ‘/folders/myfolders/cert/input’;
Data miss;
Set cert.input04;
Array vars(*) _numeric_; . Waral dи,
Do i=1 to dim(vars);
If vars(i)=. then vars(i)=0;
End;
Drop I;
Run;
Proc print;
Run;
5. 写一个array,把var12-var15所有的missing value变0
Libname cert ‘/folders/myfolders/cert/input’; . 1point3acres.com
Data miss;
Set cert.input004;
Array vars(4) var12-var15;/注意:array的名字Vars不能和变量的名字重复,变量名字是var没有s
Do i=1 to 4 .1point3acres
If vars(i)=. then vars(i)=0;/注意:这里是Array的名字
End; . ----
Drop I;
Run; ..
Proc print;
Run;
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; . From 1point 3acres bbs
return(cm);
endsub;
run;
options cmplib=work.function;
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中
. 1point 3acres
proc import datafile=’/folders/myfolders/certadv/ABCDE.xlsx’
dbms=xlsx .--
out=abcde -baidu 1point3acresreplace;
run;
这里跑一次
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; . From 1point 3acres bbs
Else If qq(i)=’C’ then numnum(i)=3;
Else If qq(i)=’D’ then numnum(i)=4; . 1point 3acres
Else If qq(i)=’E’ then numnum(i)=5;
End;
Run;
这里再跑第二次
%do %until (&y>2);
%put &y;
%let y=%sysevalf(&y+0.25);
%end;
%mend loop;
options mprint mlogic;
%loop(y=&x);
. check 1point3acres for more.
10. macro,用sql把region='AMR'的avg(var)存成一个macro variable 用into:mvar
.--
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 -baidu 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; ..
12. Hash form: 根据country19建立hash表,然后input contry20,根据key查表,成功的输出work.XXX, 失败的输出到work.errors。
length Country name $30; . 1point 3acres
if _n_=1 then do;
call missing(Country name); . From 1point 3acres bbs
declare hash C(dataset:'country19');
C.definekey('country_code');
C.definedata('country_name');
C.definedone();
end;
set country20;
rc=c.find( );
if rc=0 then output info19;
else output errors19;
run; . From 1point 3acres bbs
自己练习书本课后题: . 1point3acres.com
Data work.success work.fail;
Drop rc;
Length Ctname $30;
If _N_=1 then do;
Call missing (Ctname); .google и
Declare hash c(dataset:’certadv.continent’); . ----
c.definekey(‘ID’); . .и
c.definedata(‘Ctname’) . Waral dи,
c.definedone();
end;
set certadv.airports; ..
rc=c.find();
if rc=0 then output work.success; .1point3acres
else output work.fail; ..
run; . Waral dи,