gpt4 book ai didi

SAS 数组 跳跃 10

转载 作者:行者123 更新时间:2023-12-02 09:10:27 24 4
gpt4 key购买 nike

我想实现相同的输出,但不是使用 var1 - var10 之类的东西对每个数组元素进行编码,但这会跳动 10 个,就像几十年一样。

data work.test(keep= statename pop_diff:);
set sashelp.us_data(keep=STATENAME POPULATION:);

array population_array {*} POPULATION_1910 -- POPULATION_2010;
dimp = dim(population_array);
/* here and below something like:
array pop_diff_amount {10} pop_diff_amount_1920 -- pop_diff_amount_2010;*/

array pop_diff_amount {10} pop_diff_amount_1920 pop_diff_amount_1930
pop_diff_amount_1940 pop_diff_amount_1950
pop_diff_amount_1960 pop_diff_amount_1970
pop_diff_amount_1980 pop_diff_amount_1990
pop_diff_amount_2000 pop_diff_amount_2010;

array pop_diff_prcnt {10} pop_diff_prcnt_1920 pop_diff_prcnt_1930
pop_diff_prcnt_1940 pop_diff_prcnt_1950
pop_diff_prcnt_1960 pop_diff_prcnt_1970
pop_diff_prcnt_1980 pop_diff_prcnt_1990
pop_diff_prcnt_2000 pop_diff_prcnt_2010;

do i=1 to dim(population_array) - 1;
pop_diff_amount{i} = population_array{i+1} - population_array{i};
pop_diff_prcnt{i} = (population_array{i+1} / population_array{i} -1) * 100;
end;

RUN;

我仍然是初学者,因此我不确定这是否可能或容易实现。谢谢!

最佳答案

不是自动的,但也不是那么困难。首先创建名称的数据集,然后转置并使用未执行的集引入名称,然后定义数组。请注意如何使用 [*] 和 name: 定义数组,就像您对 Population_array 所做的那样。

data names;
do type = 'Amount','Prcnt';
do year=1920 to 2010 by 10;
length _name_ $32;
_name_ = catx('_','pop_diff',type,year);
output;
end;
end;
run;
proc print;
run;
proc transpose data=names out=pop_diff(drop=_name_);
var;
run;
proc contents varnum;
run;

data pop;
set sashelp.us_data(keep=STATENAME POPULATION:);
array population_array {*} POPULATION_1910 -- POPULATION_2010;

if 0 then set pop_diff;
array pop_diff_amount[*] pop_diff_amount:;
array pop_diff_prcnt[*] pop_diff_prcnt:;
do i=1 to dim(population_array) - 1;
pop_diff_amount{i} = population_array{i+1} - population_array{i};
pop_diff_prcnt{i} = (population_array{i+1} / population_array{i} -1) * 100;
end;
run;
proc print data=pop;
run;

enter image description here

enter image description here

关于SAS 数组 <array-elements> 跳跃 10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52937393/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com