注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
SAS base 经验分享:分享一下考SAS时候的小经验。我网上报名了。第一次在家里的电脑,data 有点问题,没下载下来,他们给我安排了第二次免费考试还是在家里,可能受疫情的影响,结果考试当天的题目launch不了,又等了5天才reschedule 的,在家里试了一下是不是可以下载下那个sample example 的题目,结果不能。因为担心正式考试的时候可能题目还不能launch。只好又重新reschedule到了Columbus 的一个考试中心。因此我建议如果报名了是在家里考试,先试试一下家里的电脑是不是可以下载下来他们的一个sample exam。这样子防止碰到考题不能launch 的问题,还的等至少5天。
那个70题一定要努力的能明白,还有那个还有一个Practice Exam, 是免费的。我当时在考试前,每隔1天,做一次,做了4次吧。 .1point3acres
我在网上看到的一个lab总结的挺好的,分享一下:题目可能不是一样子的,但是考的点是差不多的。希望对大家有所帮助:
Sasperformancebasedlab题目机经汇总
用libname建立input和output的library
libnamecert “path”;
libnameresult “path”;
1. 用libname读一个xlsxfile的名字
Code:
libnamewenjian xlsx “file_path”;.1point3acres
proc contents data = wenjian._all_;
run;
求means如下:
Code:
proc means data = wenjian.sheet1;
<var col1 col2;>
run;.google и
proc contents data = wenjian.sheet1;
run;
.1point3acres
2. Given a dataset cert.input01 with several variables (ID, Postal_code, income, etc.). Build a new dataset results.output01 based on given dataset, only keep the observations with highest income for each Postal_code.特别注意还有最后一步,再把结果按income按ascending排列。
proc sort data=cert.input01 out= test;
By postalcode descending income;. ----
Run;
. .и
Data results.output01;
Set test;
By postalcode;
If last.postalcode then output;
Run;. check 1point3acres for more.
3. 考字符串的提取,之前看的机经,只准备了提取单词的scan(), 结果这次考得是提取数字..好像是customerid=CST23455, 提取出‘23455’as newvar, 、/*并转化成numeric*/,似乎用substr() 同时name中如果含有“z”或者 “Z”,输zflag=1,else zflag=0. 2. 需要count zflag有多少个0,多少个1。
-baidu 1point3acres
第一部分:读取id,并转化成数值型
data test;
set pg2.np_weather;
keep station a;
a = input(substr(station,4),best12.);
run;
第二部分:找到含有特殊字符的并计数(用了sashelp.cars用model里面有’2’zflag = 0,有‘4‘ zflag = 0.)
data test;
set sashelp.cars;
keep make model zflag;
if find(model,'2') ne 0 or find(model,'4') ne 0 then zflag = 1;
else zflag = 0;
run;. From 1point 3acres bbs
proc sort data = test out=sorted;
by zflag;
run;.1point3acres
4. Given a dataset and output its observations to three subsets based on conditions (age).. 1point 3 acres
data cheapcarsregularcarsluxurycars;
set sashelp.cars;
if msrp< 20000 then output cheapcars;
else if msrp>= 20000 and msrp<= 30000 then output regularcars;
else output luxurycars;
run;
5. Merge two datasets with common variable. One dataset contains variables Product and Qty, another contains variables Product and Price.
Merge之前要先把表格按commonvariablesort一下。(使用的是sashelp.class和sashelp.classfit表格)
proc sort data=sashelp.classfit out=sortedclassfit;
by name;
run;
data test; ..
merge sashelp.classsortedclassfit;. 1point 3acres
by name;
run;. 1point3acres.com
6. Given a data set cert.input05 which is students' roster. One variable is 'major' and it may contain things like 'Physics', 'History and Math' or 'Statistics and Computer Science'. If an 'and' is included then put the first major into 'major' and put the second one into 'second major'.还问有多少同学来自同一个州
用sashelp.cars表格。找model里面是否有4dr字符,有的话就把后面的当做是second_model(类比secondmajor),把前面的作为new_model。
data cars;
set sashelp.cars;
keep make model new_modelsecond_model;
if find(model,'4dr') ne 0 then do;
new_model = substr(model,1,find(model,'4dr')-1);
second_model = substr(model,find(model,'4dr')+4);.1point3acres
end;
else do;
.1point3acresnew_model = model;
end;
run;
或者不创建新的new_model,直接用原来的,但是注意在if里面要先写新的column
data cars;
set sashelp.cars;. Waral dи,
keep make model second_model;
if find(model, '4dr') ne 0 then.--
do;
second_model=substr(model, find(model, '4dr')+4);
model=strip(substr(model, 1, find(model, '4dr')-1));
end;
run;.google и
第二问,有多少同学来自同一个州。(用有多少辆车来自同一个origin代替)
proc sort data=sashelp.cars out=sortedcars;
by origin;
run;
data count;
set sortedcars;
by origin;
if first.origin then count=0;
count + 1;
if last.origin;
run;
第三问多个筛选条件
data test;
set cars;
where origin = 'Asia' and type = 'Sports' and second_model = '';
run;
7. 还有一个project的数据表里面的变量有firstname和lastname,让把两个变量的数据concatenate成一个新的变量叫fullname,需要fullname的长度刚好是最长的那个record的长度,这个我是先把fullname的长度定义成了20,然后发现有warning,再试了30没有warning,然后试25有warning,就从25一个一个往上加直到刚好没有warning,最后答案好像是27还是28没记清。然后还是这个project,让把firstname和lastname中有z和Z的observation都subset出来,然后回答了1-2个问题。
data cars;
set sashelp.cars;
keep make model name Alistblist;.
name = catx('-',make,model);
if find(model,'A') ne 0 THEN Alist = model;
if find(model,'a') ne 0 then blist = model;
run;
8. 改错题
考输出多个dataset,根据一个变量,好像是家具类型吧,chair/sofa/tables输出三个数据库。然后问你chair啊,sofa啊这个数据库有多少个obs,mean啊,第几个obs id是什么啊。
错误1:引号里的内容的大小写错误
错误2:题目里用的都是ifthen,ifthen,最后出现了else,只要把else删去,再加上一个if语句即可
9. 改错题
数据表中有一个变量叫firstname,然后需要找出指定的first name (有Amanda, Tao, Chen, ...),如果它们是连续出现在原来的数据表中的话,就要建立一个increment variable叫count,对应的count值是0, 1, 2, 3,...这个样子。如果没有连续出现,这个observation对应的count值就是0. 题目给出的code里面有:.1point3acres
data dataname;
set rawdataname;
by firstname;
if firstname in (‘AMANDA’ ‘TAO’ ‘CHEN’) then do; . 1point3acres.com
if first.firstname then count=0;
count=count+1;. .и
(下面的code记不清了,还原的可能有问题)
else count=0;
end;
run;. ----
错误1:把count=count+1 改成count+1。因为原先的code不retain.1point3acres
错误2:括号内的内容大小写错误并且没有加逗号
if firstname in (‘AMANDA’ ‘TAO’ ‘CHEN’) then do; . ----
应改为 if firstname in (‘Amanda’,‘Tao’,‘Chen’) then do;
|