Q4: 机经每日一练的第九题, 提取ID中的数字部分,注意input和substr结合在一起的用法,考试的时候,没有计算b的过程,所以必须要用input把character转成numeric找答案。
libname cert 'C:\cert\input';
libname results 'C:\cert\output';. From 1point 3acres bbs
data results.output09;
set cert.input09;
a=input(substr(custID, 3, 6), 4.);
run;
proc print data=results.output09;. .и
run;
Q5: 机经每日一练的第十题,记得先用catx合并firstname和lastname,考试只问了zflag
libname cert 'C:\cert\input';
libname results 'C:\cert\output';.
data results.output10(drop=firstname lastname);
set cert.input10;
fullname=catx(' ', firstname, lastname);-baidu 1point3acres
z=find(fullname, 'z', 'i');
if z ne 0 then do;
zflag=1;
nozflag=0;
end;
else if z=0 then do;
zflag=0;
nozflag=1;
end;. 1point3acres
run;
proc print data=results.output10;
sum zflag nozflag; run;
Q6: 机经每日一练中的第十五题,给了两个datasets, One dataset contains variables Product and Qty, another contains variables Product and Price. 要求在输出的output dataset中新建一个variable名叫total, total = Qty * Price,后面问了某些observation的the grant total price和mean total price. check 1point3acres for more.
libname cert 'C:\cert\input';
libname results 'C:\cert\output';
proc sort data=cert.input15a out=sort_input15a;
by product;. 1point3acres
run;
proc sort data=cert.input15b out=sort_input15b;
by product; ..
run;
data results.output15;
merge sort_input15a sort_input15b;
by product;
total=price*qty;. 1point 3 acres
run;
proc print data=results.output15(obs=3 firstobs=3); .. var total;-baidu 1point3acres
run;
proc means data=results.output15(obs=6 firstobs=6) mean;. 1point 3acres
var total;
run;
Q7:改错题, 机经每日一练的第二题类似题,输出的是三个分别关于beds, chairs, sofas的data sets,没有format,错误的地方:开头需要用libname cert读入数据,if…then output中大小写没有一致,最后一个语句不是else,是if。
libname cert 'C:\cert\input';
data beds chairs sofas;
set cert.input07;
if name='Bed' then output beds;
if name='Chair' then output chairs;. 1point3acres.com
if name='Sofa' then output sofa;
run;
proc print data=beds;
run;
proc print data=chairs;
run;
proc print data=sofas;
run;
Q8: 改错题,机经每日一练中的第十一题,同样需要注意大小写和first.name的用法
libname results 'C:\cert\output';
proc sort data=cert.input11 out=test11std;
by name;
run;
data output11;
set test11std;
by name;
if name in ('Amanda', 'Tao', 'Chen') then
do;. 1point3acres
if first.name then count=0;
count+1;
end;
else count=0;
run;
proc print data=output11;
run;
. 1point 3acres 填空题:
如何定义Macro variable,选%let.
Proc transpose中var, id, by后面分别填什么, 参考机经每日一练的第七题
给了一个笔记本dat格式的截图,问Proc import中dbms=? 我写的是cvs,不太确定
%let中,如何引用variable,我写在机经每日一练里面了,注意如果是character一定是双引号,单引号不对