----------------------------------------------------------------------------------------------------------------------------
LAB我自己总结的机经:(数据用的是课本的附带数据,只有一个ARRAY题(第七题)我自己构建了一个简单的dataset。
. check 1point3acres for more. 1. 在proc SQL里创立一个table,table里读取某个文件所有的变量,但只显示另外一个文件里NAME存在的观察。
. 1point3acres.com
where name in (select name in cert.XXXX). 1point3acres.com
. Χ 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' ..
when RevCargo < 24000 then 'middle'
else 'high'
end as new_var3
from certadv.cargorev;
quit;
3. 让你建一个maro,在do loop里面写一个if语句;
%macro loop(start,end);
%do i =&start %to &end;
%if &i>10 %then %do;
data x&i; . From 1point 3acres bbs
x=&i;
run;
%end;
%end;
%mend;
%loop(1,200);
.-- 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; . 1point3acres
End;
Drop I;
Run;
Proc print; ..
Run;
. ----
5. 写一个array,把var12-var15所有的missing value变0
Libname cert ‘/folders/myfolders/cert/input’;
Data miss;
Set cert.input004; . check 1point3acres for more.
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; . 1point 3 acres
Proc print;
Run;
. 1point 3 acres
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;
function add(inch);
cm=inch*2.45;
return(cm);
endsub;
run;
options cmplib=work.function;
data work.height;
set certadv.all;
Height=add(fee);
Run;
Proc print data=work.Height;
Run;
proc import datafile=’/folders/myfolders/certadv/ABCDE.xlsx’
dbms=xlsx . From 1point 3acres bbs
out=abcde
replace;
run;
这里跑一次 . 1point3acres.com
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;
Else If qq(i)=’E’ then numnum(i)=5;
End;
Run;
这里再跑第二次
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();
end;
set country20;
rc=c.find( );
if rc=0 then output info19;
else output errors19;
run;
自己练习书本课后题: . Waral dи,
Data work.success work.fail;
Drop rc;
Length Ctname $30;
If _N_=1 then do;
Call missing (Ctname);
Declare hash c(dataset:’certadv.continent’); . 1point3acres
c.definekey(‘ID’); .1point3acres
c.definedata(‘Ctname’)
c.definedone();
end;
set certadv.airports; . ----
rc=c.find();
if rc=0 then output work.success;
else output work.fail; . Χ
run; . check 1point3acres for more.