- 48
- 0
- 约1.05万字
- 约 15页
- 2020-02-14 发布于广东
- 举报
1. Two ways to select every second row in a data set
data example;
set sashelp.class;
if mod(_n_,2) eq 0;
run;
MOD Function returns the remainder from the division of the first argument by
the second argument. _N_ corresponds to each row. The second row would be
calculated like (2/2) which returns zero remainder.
data example1;
do i = 2 to nobs by 2;
set sashelp.class point=i nobs=nobs;
output;
end;
stop;
run;
2. How to select every second row of a group
Suppose we have a table sashelp.class. We want every second row by variable sex.
proc sort data = sashelp.class;
by sex;
run;
data example2 (drop = N);
set sashelp.class;
by sex;
if first.sex then N = 1;
else N +1;
if N = 2 then output;
run;
3. How to calculate cumulative sum by group
Create Sample Data
data abcd;
input x y;
cards;
1 25
1 28
1 27
2 23
2 35
2 34
3 25
3 29
;
run;
Cumulative Sum by Group
Cumulative Sum by X
data example3;
set abcd;
if first.x then z1 = y;
else z1 + y;
by x;
run;
4. Can both WHERE and IF statements be used for subsetting on a
newly derived variable?
SAS : WHERE vs. IF
No. Only IF statement can be used for subsetting when it is based on a newly
derived variable. WHERE statement would return an error newly derived
variable is not on file.
Please note that WHERE Option can be used for subsetting on a newly created
variable.
data example4 (where =(z =50));
set abcd;
z = x*y;
run;
5. Select the Second Highest Score with PROC SQL
data example5;
input Name $ Score;
cards;
sam 75
dave 84
sachin 92
ram 91
;
run;
proc sql;
select *
from example5
where score in (select max(score) from example5 where score not in (select max(score)
from example5));
quit;
6. Two ways to create a macro variable that counts the number of
observations in a dataset
data _NULL_;
if 0 then set sashelp.class nobs=n;
您可能关注的文档
最近下载
- 陕汽F3000系列车型电器系统介绍.pdf VIP
- 2025年内蒙古自治区中考道德与法治真题试卷含详解.pdf VIP
- 新教材人教版高中数学必修第二册全册教案(教学设计).doc VIP
- 2025年春绩优学案七年级历史下册通用版答案.pdf VIP
- 年产18万吨合成氨一氧化碳变换工段工艺设计.docx VIP
- 检验科心肌酶项目课件.pptx VIP
- 装修工程施工方案简单版(3篇).docx VIP
- 湖北省高考:2025年-2023年《地理》考试真题与参考答案 .pdf VIP
- 【中考真题】2025年湖南省益阳市中考数学试卷(附答案) .pdf VIP
- NBT 20121-2012 核电工程施工组织设计编制规定.pdf VIP
原创力文档

文档评论(0)