由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - Please help me with SAS! Thank you!
相关主题
SAS format 的问题完全不懂SAS,急请教一个问题
问个效率问题 SQL vs data step,大数据量Proc SQL 能不能直接读 非 SAS format 的数据,txt , csv 等
SAS - please help!关于SAS interview
珍惜生命,远离hsbc。求推荐学习sas proc sql , macro的资料
求救:SAS programmer面试题!SAS菜鸟请教如果使SAS的output的结果放到一个文件内?
which route in SAS is faster?PROC SQL join data help
为什么合并这两个数据不能用sas merge 而要用SAS SQLSAS help : Proc dataset
请教一个SAS SQL的问题SAS Base 70题 第20题求教
相关话题的讨论汇总
话题: 1981话题: sas话题: year话题: age话题: population
进入Statistics版参与讨论
1 (共1页)
s**f
发帖数: 365
1
So sorry I can't type Chinese now. Please help me with a SAS question. I am
still learning the basics of SAS, please bear with me. thank you!
There is a dataset below, how can I calculate the sum of "population" for
age 24-44, 49-64, and 69-85 for each year in SAS?
Year age population
1981 4 ***
1981 9 ***
1981 14 ***
1981 19 ***
1981 24 ***
1981 29 ***
1981 34 ***
1981 39 ***
1981 44 ***
1981 49 ***
1981 54 ***
1981 59 ***
1981 64 ***
1981 69 ***
1981 74 ***
1981 79 ***
1981 84 ***
1981 85 ***
1982 4 ***
1982 9 ***
1982 14 ***
1982 19 ***
1982 24 ***
...
...
...
How can I generate a new dataset contains the following information?
Year age population
1981 24-44 ###
1981 49-64 ###
1981 69-85 ###
1982 24-44 ###
1982 49-64 ###
1982 69-85 ###
1983 24-44 ###
1983 49-64 ###
1983 69-85 ###
...
...
p********a
发帖数: 5352
2
select year,"24-44" as age_cat, sum(population) as population from dst where
24<=age<=44 group by year
union
select year,"49-64" as age_cat, sum(population) as population from dst where
49<=age<=64 group by year
union
select year,"69-85" as age_cat, sum(population) as population from dst where
69<=age<=85 group by year
h********o
发帖数: 103
3
proc sql;
select year,"24-44" as age,sum(population) as population
from one
where age between 24 and 44
group by year
union
select year,"49-64" as ageRange,sum(population) as total
from one
where age between 49 and 64
group by year
union
select year,"69-64" as ageRange,sum(population) as total
from one
where age between 69 and 85
group by year
order by year;
quit;
h********o
发帖数: 103
4
Sorry, The "ageRange" should be changed to "age"
s**f
发帖数: 365
5
Thank you for replying, doesn't look like SAS entry level coding ah.
I am still at DATA ###; PROC ###; RUN; level.

where
where
where

【在 p********a 的大作中提到】
: select year,"24-44" as age_cat, sum(population) as population from dst where
: 24<=age<=44 group by year
: union
: select year,"49-64" as age_cat, sum(population) as population from dst where
: 49<=age<=64 group by year
: union
: select year,"69-85" as age_cat, sum(population) as population from dst where
: 69<=age<=85 group by year

s**f
发帖数: 365
6
Thank you for replyin! I know nothing about SQL, need to read more.
I am still at DATA ###; PROC ###; RUN; level.

【在 h********o 的大作中提到】
: proc sql;
: select year,"24-44" as age,sum(population) as population
: from one
: where age between 24 and 44
: group by year
: union
: select year,"49-64" as ageRange,sum(population) as total
: from one
: where age between 49 and 64
: group by year

h********o
发帖数: 103
7
For the entry level,you can do it like this:
data one two three;
set orig;
if 24 <= age <= 44 then output one;
if 49 <= age <= 64 then output two;
if 69 <= age <= 85 then output three;
run;
proc sort data = one;
by year;
run;
proc sort data = two;
by year;
run;
proc sort data = three;
by year;
run;
data one;
set one;
drop age;
ageRange = "24-44";
by year;
if first.year then sum = 0;
sum + population;
if last.year;
run;
data two;
set two;
drop age;
ageRange = "49-64";
by year;
if first.year then sum = 0;
sum + population;
if last.year;
run;
data three;
set three;
drop age;
ageRange = "69-85";
by year;
if first.year then sum = 0;
sum + population;
if last.year;
run;
data final(rename = (sum = population
ageRange = age));
set one two three;
drop population;
run;
proc sort data = final;
by year;
run;
s**f
发帖数: 365
8
Hi! I am looking the SAS documentation for SQL now. I definitely need SQL.
Thank you for the entry level codes!

【在 h********o 的大作中提到】
: For the entry level,you can do it like this:
: data one two three;
: set orig;
: if 24 <= age <= 44 then output one;
: if 49 <= age <= 64 then output two;
: if 69 <= age <= 85 then output three;
: run;
: proc sort data = one;
: by year;
: run;

o****o
发帖数: 8077
9
no one even ever mentioned FORMAT, i.e. formated class variable?
j******o
发帖数: 127
10
Format should be more efficient.

【在 o****o 的大作中提到】
: no one even ever mentioned FORMAT, i.e. formated class variable?
b*****e
发帖数: 223
11
用 proc format 重新 code: age 24-44, 49-64, and 69-85 -》 产生一个新 var
然后用 proc freq 对 Year 和这个 新 var 求和
s**f
发帖数: 365
12
Hao!

【在 b*****e 的大作中提到】
: 用 proc format 重新 code: age 24-44, 49-64, and 69-85 -》 产生一个新 var
: 然后用 proc freq 对 Year 和这个 新 var 求和

s******r
发帖数: 1524
13
efficient in coding, inefficient in running.

【在 j******o 的大作中提到】
: Format should be more efficient.
1 (共1页)
进入Statistics版参与讨论
相关主题
SAS Base 70题 第20题求教求救:SAS programmer面试题!
sas base 70 第 20题which route in SAS is faster?
SAS format file--- when I load the file 急~~~谢谢~~~为什么合并这两个数据不能用sas merge 而要用SAS SQL
question about proc format请教一个SAS SQL的问题
SAS format 的问题完全不懂SAS,急请教一个问题
问个效率问题 SQL vs data step,大数据量Proc SQL 能不能直接读 非 SAS format 的数据,txt , csv 等
SAS - please help!关于SAS interview
珍惜生命,远离hsbc。求推荐学习sas proc sql , macro的资料
相关话题的讨论汇总
话题: 1981话题: sas话题: year话题: age话题: population