使用基本SAS中的频率桶创建表
以下是我的数据集示例: 城市日 亚特兰大10 坦帕95 亚特兰大100 夏洛特20 夏洛特31 坦帕185 我想将“天”分解为0-30、30-90、90-180、180+的桶,这样“桶”沿着桌子的x轴,城市沿着y轴使用基本SAS中的频率桶创建表,sas,Sas,以下是我的数据集示例: 城市日 亚特兰大10 坦帕95 亚特兰大100 夏洛特20 夏洛特31 坦帕185 我想将“天”分解为0-30、30-90、90-180、180+的桶,这样“桶”沿着桌子的x轴,城市沿着y轴 我尝试使用PROC FREQ,但我没有SAS/STAT。在基本SAS中有什么方法可以做到这一点吗 我相信这就是你想要的。这无疑是一种“暴力”方法,但我认为它正确地概括了这一概念 data have; length city $9; input city dayscount; card
我尝试使用PROC FREQ,但我没有SAS/STAT。在基本SAS中有什么方法可以做到这一点吗 我相信这就是你想要的。这无疑是一种“暴力”方法,但我认为它正确地概括了这一概念
data have;
length city $9;
input city dayscount;
cards;
Atlanta 10
Tampa 95
Atlanta 100
Charlotte 20
Charlotte 31
Tampa 185
;
run;
data want;
set have;
if dayscount >= 0 and dayscount <=30 then '0-30'n = dayscount;
if dayscount >= 30 and dayscount <=90 then '30-90'n = dayscount;
if dayscount >= 90 and dayscount <=180 then '90-180'n = dayscount;
if dayscount > 180 then '180+'n = dayscount;
drop dayscount;
run;
数据已经存在;
城市长度9美元;
输入城市日记帐;
卡;
亚特兰大10
坦帕95
亚特兰大100
夏洛特20
夏洛特31
坦帕185
;
跑
数据需求;
集有;
如果dayscount>=0,dayscount=30,dayscount=90,dayscount=180,则“180+”n=dayscount;
落日童子军;
跑
解决此问题的方法之一是使用Proc Format分配值桶,然后使用Proc Transpose获得所需结果:
data city_day_split;
length city $12.;
input city dayscount;
cards;
atlanta 10
tampa 95
atlanta 100
charlotte 20
charlotte 31
tampa 185
;
run;
/****Assigning the buckets****/
proc format;
value buckets
0 - <30 = '0-30'
30 - <90 = '30-90'
90 - <180 = '90-180'
180 - high = 'gte180'
;
run;
data city_day_split;
set city_day_split;
day_bucket = put(dayscount,buckets.);
run;
proc sort data=city_day_split out=city_day_split;
by city;
run;
/****Making the Buckets as columns, City as rows and daycount as Value****/
proc transpose data=city_day_split out=city_day_split_1(drop=_name_);
by city;
id day_bucket;
var dayscount;
run;
相当肯定PROC FREQ是一个基本PROC。
> **city |0-30 |90-180 |30-90 |GTE180**
> Atlanta |10 |100 |. |.
> Charlotte |20 |. |31 |.
> Tampa |. |95 |. |185