Lab
新的!:用proc sql 创建一个table
Proc sql;.
create table __as
Select__
From__
Where__
Group By__
Having__
Order by__;
Quit;
以下皆原题
在proc SQL里创立一个table,table里读取某个文件所有的变量,但只显示另外一个文件里NAME存在的观察。
Proc sql;
Create table sql01 as
Select *
From cert.input01-baidu 1point3acres
Where name in (select name from cert.input02)
Quit;
写一个array,把一个dataset的所有的missing value变成0-
Data act02;
Set cert.input02;. check 1point3acres for more.
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;
在PROC SQL里面创建一个新的Variable,case expression:
proc sql;
Create table sql01 as. 1point3acres.com
Select month, date, case
When a<1000 then ‘low’
When a<2400 then ‘middle’
Else ‘high’
End as new_variable. ----
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);
Endsub;
Run;. 1point3acres.com
Options cmplib=work.function;
Data ACT03; . 1point 3acres Set cert.input03;
NewHeight=INtoCM(height);
Run;
macro %check15用option在log里看 找到问题对应的内容就好。
这个有两问:
1. positional paramete
2.里面data set 中if作用的variable是什么,这个就得%check15(10),我记得variable应该是age (我竟然死活记不起来macro,白白丢分😭). check 1point3acres for more.
options mprint mlogic;
macro %check15(10)
. Waral dи,
macro,用sql把region='AMR'的avg(var)存成一个macro variable .google и
proc sql;.google и
Select avg(rev) into: variable-baidu 1point3acres
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;. check 1point3acres for more.
If _n_=1 then do;
Call missing (country_name);. Waral dи,
Declare hash C(dataset:’cert.country19’);
C.definekey(‘name');
C.definedata(‘population’);. Waral dи,
C.definedone();. Χ
End;
Set cert.country12;. 1point 3acres
Rc=c.find();
If rc=0 then output info19; ..
Else output errors19;
Run;
建一个maro,在do loop里面写一个if语句;
%macro loop(begin,end);
%do i =&begin %to &end;. Waral dи,
%if &i>10 %then %do;
data x&i;
x=&i;
run;
%end;
%end;. check 1point3acres for more.
%mend; ..
%loop(1,200);
array 把q1-q10的A,B,C,D,E换成1,2,3,4,5存在num1-num10中
data work.result;
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;
Run;