所以如果没有windows 或者windows 很老担心出问题,去onsite 应该也行。
. .и 二、考试题目(后面我贴出我平时准备时练习的代码,接近原题,基本包括考试的所有题型)
我遇到的Project:
SQL
1. 从一个表中读name,要求name必须在另一个表的name中
select name from a
where name in (select name from b);
2. 从一个表中选 unique Make and Type, 从另一个表中匹配Rebate,有对应的Make 和 Type 则显示Rebate,否则为空。我自己用left join 做的。
select distinct c.Make, c.Type, r.Rebate from table1 c left join table2 r on
c.Make=r.Make and c.Type=r.Type
3. 从一个表中选择某一列并取平均值,将这个平均值给一个宏变量。. 1point3acres
4. 从一个表中选某列的平均值,附加一些一些条件,并做排序。
Mac 类
1. %Check(10)
前面我加了 options mprint symbolgen
我选的 parameter 为 ‘N’, 第二问我填的 age
2. 写一个含有comment的macro(comment的内容不能执行),
后面macro的内容是一个proc print的语句,最后执行这个macro
. From 1point 3acres bbs
3.用sql把region='AMR'的avg(var)存成一个macro variable -baidu 1point3acres
Array 类
1. inch to centimeters
.google и
2. 所有的missing value 全部变成0. 1point3acres
四、我参考上述机经后准备的练习代码,应对考试题型基本没啥问题,数据在附件中,自己建一个也可以。
另外,强烈建议考前做以下那个practice,很有帮助
/*********************************************************************************
Prepare data
X1 and X2 are used as inputs.
/*********************************************************************************/
libname cert '/folders/myfolders/Certification_SAS for beginners_SAS codes/Cert_base/input/';
libname new xlsx '/folders/myfolders/Certification_SAS for beginners_SAS codes/Cert_base/input/input01.xlsx';. 1point 3 acres
.--libname out '/folders/myfolders/Certification_SAS for beginners_SAS codes/Cert_base/output/';
.
data x1;
set new.sheetc;. ----
run;. Χ
data x2;
set new.sheeta;
run;. Χ
proc sql;
select * from dictionary.indexes
where libname=’SASUSER’ and memname=’SALE2000’;. check 1point3acres for more.
quit;
/*********************************************************************************/-baidu 1point3acres
/*Function*/
/*********************************************************************************/
/*---------------------------------------------
Function Exmple 1
proc fcmp IN to CM, 建好function后options cmplib=work.functions,然后建个新data里面
有个新列newheight=IN to CM(height)cm=2.45IN . Waral dи,----------------------------------------------*/
proc fcmp outlib=work.functions.dev;
function in2cm(in);
return(in*2.54);.--
endsub;
options cmplib=work.functions;
Data ACT03;
Set x1;. 1point3acres.com
NewHeight=in2cm(height);. Χ
Run;
/*---------------------------------------------
Function Exmple 2
Weight change: lbs to kg
----------------------------------------------*/
proc fcmp outlib=work.a.c;
Function l2k(l);
k=0.9*l;
return(k);
endsub;. Waral dи,
run;
.1point3acres
options cmplib=work.a;
data x2;
set x1;
new_weight=l2k(weight);
run;
-baidu 1point3acres
/*---------------------------------------------
Function Exmple 3
String as input. 数据集需要添加name= first name + second name,没时间就没加
----------------------------------------------*/. Χ
options cmplib=(work.functions);
proc fcmp outlib=work.functions.dev;
function ReverseName(name $) $ ;
length newname $40;-baidu 1point3acres
newname=catx(' ',scan(name,2,','),scan(name,1,','));
return (newname);
endsub;
data xx;. 1point 3acres
set yy;.google и
zz=ReverseName(Name);
run;
/*********************************************************************************
Array https://support.sas.com/resource ... s/sugi30/242-30.pdf
*********************************************************************************/
/*---------------------------------------------
Arrary Exmple 1 . .и
Change all missing value to 0
----------------------------------------------*/
data new;. Waral dи,
set x1;
array var(*) _numeric_;
do i=1 to dim(var);
if var(i)=. then var(i)=0;
end;
drop i;
run;
. .и
. .и
/*---------------------------------------------. 1point3acres.com
Arrary Exmple 2 ..
把q1-q3的A,B,C,D,E换成1,2,3,4,5存在num1-num3中
----------------------------------------------*/. ----
data new2;
set x1;.google и
array q(3) q1-q3;
array num(3) num1-num3;
do i=1 to 3;
if q(i)='A' then num(i)=1;
else if q(i)='B' then num(i)=2;
Else If q{i}='C' then num(i)=3;
Else If q{i}='D' then num(i)=4;
Else If q(i)='E' then num(i)=5;
end;
run;
.1point3acres
.google и
/*---------------------------------------------
Arrary Exmple 3
写一个array LS,有LENGTH1-LENGTH3, 另外一个array NEW,NEWLENGTH1-NEWLENGTH3.
有一个data set,LS单位是in,NEW是换算后的cm,NEW(i)=2.54*LS(i)
----------------------------------------------*/
data ls;
set x1;
array ls(*) LENGTH1-LENGTH3;
array new(*) NEWLENGTH1-NEWLENGTH3;
do i =1 to 3;
NEW(i)=2.54*LS(i);
end;
drop i;.1point3acres
run;
. Χ
. 1point 3acres
/*********************************************************************************/
/*SQL*/
/*********************************************************************************/
/*---------------------------------------------. From 1point 3acres bbs
SQL Exmple 1
----------------------------------------------*/
Proc sql;
Create table sql01 as
Select *
From x1
Where name in (select name from x2);
Quit;
proc sql;
create table new_table as
select name, height, case
when height >=180 then 'high'. From 1point 3acres bbs
when height >=170 and height <180 then 'middle'
when height <170 then 'low' . 1point3acres
end as height_marker from x1;
quit;. 1point 3 acres
..
/*---------------------------------------------
SQL Exmple 3 . 1point3acres
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;
select distinct x2.name, height, gender, benefit from x1 right join x2 on
x1.name=x2.name;
quit;
/*---------------------------------------------
SQL Exmple 4
给选出来的变量加label (select x label="foo", y)
----------------------------------------------*/ ..
proc sql;
select name label='Student Name', n1 label='Index1' from x1;
quit;
/*---------------------------------------------
SQL Exmple 5
having avg大于150 用department进行分组,按着一个variable进行sort
----------------------------------------------*/
proc sql;
create table xx as
select department, avg(height) as hei from x1. 1point 3 acres
group by department
having hei>150
order by department;
quit;
-baidu 1point3acres
/*---------------------------------------------
SQL Exmple 6. From 1point 3acres bbs
Use dictionary.columns to get the list of variable name of a table. .и
----------------------------------------------*/
proc sql;
select name into: collist separated by ','. 1point3acres
from dictionary.columns
where libname='WORK' and memname='X1' and name like '%ght';
quit;
Data info19 errors19;
Length country name $30;
If _n_=1 then do;
Declare hash C(dataset:'cert.country19');
C.definekey('name');
C.definedata('population');. .и
C.definedone();
Call missing (country,name);
end;
.1point3acres
set cert.country12;
rc=c.find(); /*rc=return code*/
if rc=0 then output info19;
else output errors19;
run;
-baidu 1point3acres
data _null_;
length fruit $10. amount 8.;
if _n_ = 1 then do ;
. .и/*Declare Hash Object*/
declare hash myhash (dataset:'hash_sample',duplicate:'r');/*Replace the duplicate, only keep the last one*/
rc = myhash.definekey('fruit');
rc = myhash.definedata('fruit','amount');
rc = myhash.definedone();
. From 1point 3acres bbs
call missing(fruit,amount); /*When no matching values, return none*/
end; . 1point 3acres . 1point3acres
/*Check*/
rc=myhash.find(key:'cherry'); /*find if cherry exist*/
if rc=0 then do; /*rc=0: find cherry*/. ----
put fruit= amount= ; . From 1point 3acres bbsend;
/*Check and Replace*/
rc=myhash.check(key:'tomato');.
if rc=0 then do;
put 'tomato is exist';
rc = myhash.replace(key:'tomato',data:'tomato',data:350);
end;
/*Find and put*/.google и
rc=myhash.find(key:'tomato');. 1point3acres
if rc=0 then do;
put 'new tomato' fruit= amount= ;.1point3acres
end;
/*Add a record*/
myhash.add(key:'peach',data:'peach',data:400);/*add new vaule*/
rc=myhash.find(key:'peach');
if rc=0 then do;
put 'new peach' fruit= amount= ;
end;. Χ
/*If not exist, then add; otherwise keep it*/.1point3acres
myhash.ref(key:'balabala',data:'balabala',data:600);
rc = myhash.find(key:'balabala');
if rc=0 then do;
put 'balbala' fruit= amount= ;
end;.--
/*Total number of records*/
totalitems = myhash.num_items;/*totalitems*/
put totalitems;
myhash.output(dataset:'out');/*Put data into 'out' dataset*/
run;
data success fail;.google и
length name $10;
call missing(name);
if _n_=1 then do;
declare hash c(dataset:'xxx');
c.definekey(yy);
c.definedata(zz,name);
c.definedone();
end;
. Waral dи,
set dajl;
if c.find() then output success;. ----
else output fail;
run;