Lab
新的!:用proc sql 创建一个table
Proc sql;
create table __as
Select__
From__
Where__
Group By__
Having__
Order by__;
Quit; .1point3acres. check 1point3acres for more.
以下皆原题
在proc SQL里创立一个table,table里读取某个文件所有的变量,但只显示另外一个文件里NAME存在的观察。
Proc sql;
Create table sql01 as
Select *. Waral dи,
From cert.input01
Where name in (select name from cert.input02)
Quit;
写一个array,把一个dataset的所有的missing value变成0-
Data act02;. .и
Set cert.input02;
Array vars(*) trip1-trip25;
do i=1 to 25 ; 原jj用的Do over vars但是我考试用了报错,所以我是先用 proc print查看了需要操作的变量然后直接用的)
If vars(i)=. Then vars(i)=0;
End;
Drop i;
Run;. 1point 3acres
在PROC SQL里面创建一个新的Variable,case expression:
proc sql;
Create table sql01 as
Select month, date, case
When a<1000 then ‘low’
When a<2400 then ‘middle’
Else ‘high’
End as new_variable-baidu 1point3acres
From cert.input01;
Quit;
proc fcmp IN to CM, 建好function后options cmplib=work.functions,然后建个新data里面有个新列newheight=IN to CM(height)cm=2.45IN
Proc fcmp outlib=work.function.dev;
Function INtoCM(inch);
Cm=inch*2.45;
Return(cm);-baidu 1point3acres
Endsub;
Run;
Options cmplib=work.function;
Data ACT03;
Set cert.input03;
NewHeight=INtoCM(height);. .и
Run;.--
options mprint mlogic;.--
macro %check15(10).google и
macro,用sql把region='AMR'的avg(var)存成一个macro variable . 1point3acres
proc sql;
Select avg(rev) into: variable
From cert.input10
Where region=’AMR’;
Quit;
Hash 根据country19建立hash表,然后input contry20,根据key查表,成功的输出work.XXX, 失败的输出到work.errors。(这道题我到现在还百思不得其解,考的时候完全按照机经写的,run的时候log说population没有被define?! 在scoreit()里面run得时候给了response code 708 也不知道是不是对的。)
Data info19 errors19;
Length country name $30;. 1point3acres.com
If _n_=1 then do;
Call missing (country_name);
Declare hash C(dataset:’cert.country19’);
C.definekey(‘name');
C.definedata(‘population’);.1point3acres
C.definedone();. 1point 3acres
End;
Set cert.country12;
Rc=c.find();
If rc=0 then output info19;. .и
Else output errors19;
Run;
建一个maro,在do loop里面写一个if语句;
%macro loop(begin,end);. 1point 3 acres
%do i =&begin %to &end;
%if &i>10 %then %do;
data x&i;.--
x=&i;
run;
%end;
%end;
%mend;
%loop(1,200);
. 1point3acres
array 把q1-q10的A,B,C,D,E换成1,2,3,4,5存在num1-num10中
data work.result;-baidu 1point3acres
SET abcde;
Drop i;
ARRAY CharNum(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;
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;. 1point3acres
Run;