将 SAS 数据集中的观测值读入数组 [英] Reading observations from SAS dataset into arrays
问题描述
这个问题与大型机上的 SAS 相关,尽管我相信在这种情况下它没有区别.
This question relates to SAS on Mainframe, although I believe it doesn't make a difference in this situation.
我有以下 SAS 数据集:
I have the following SAS dataset:
Obs DATO T_ALLOC T_FRESP
1 19328 647 1804
2 19359 654 1797
3 19390 662 1789
4 19418 676 1774
5 19449 636 1815
6 19479 698 1753
我的目标是将 3 个变量的所有 6 个观察值(我希望我在这里使用正确的术语)放入单独的数组中.
My goal is to place all 6 observations of the 3 variables (I hope I use the correct terminology here), into seperate arrays.
我花了很大的力气阅读了关于数组的工作,但出于某种原因,这个特定问题的解决方案让我望而却步.
I have made a great effort of reading up on working with arrays, but for some reason the solution for this particular problem have eluded me.
如果有人愿意伸出援助之手,我们将不胜感激.即使是包含我正在寻找的答案的文档链接,也会非常有帮助.
If anyone would be as kind as to provide a helping hand it would be much appreciated. Even a link to documentation containing the answer im looking for, would be very helpful.
如果我的解释不清楚,请告诉我,我会提供任何必要的额外信息.
If i am unclear in my explanation, please tell me so, and i will provide any additional information necessary.
提前致谢.
编辑->
我的最终 CSV 应该类似于:
My final CSV should look similar to this:
Datoer,01/2013,02/2013,03/2013,04/2013,05/2013,06/2013,07/2013,08/2013,09/2013,10/2013
Freespace,800,1000,1243,1387,1457,1562,1620,1700,1800,1900
Allokeret,1000,1200,1456,1689,1784,1865,1930,2000,2100,2200
推荐答案
如果我正确理解了你的需求,你可以在 proc transpose 的帮助下得到你想要的结果.
You can get the result you want with the help of proc transpose, if I understood your needs correctly.
proc transpose data = datain out = dataout;
var DATO T_ALLOC T_FRESP;
run;
proc export data=dataout
outfile='xxxxx\tmp.csv'
dbms=csv
replace;
run;
SQL 的另一个想法.
Just another idea with SQL.
proc sql noprint;
select DATO into :dato separated by ',' from datain;
select T_ALLOC into :talloc separated by ',' from datain;
select T_FRESP into :tfresp separated by ',' from datain;
quit;
data _NULL_;
file 'xxxxx\tmp.csv';
put "var1,&dato";
put "var2,&talloc";
put "var3,&tfresp";
run;
另一个是数组.
data _NULL_;
set datain nobs = nobs;
array data DATO T_ALLOC T_FRESP;
format t1-t3 $50.;
retain t1-t3;
array t[3] $;
do i = 1 to dim(t);
if _N_ = 1 then t[i] = put(data[i], 8.);
else t[i] = compress(t[i] || ',' || put(data[i], 8.));
end;
if _N_ = nobs;
file 'xxxxx\tmp.csv';
put "var1," t1;
put "var2," t2;
put "var3," t3;
run;
这篇关于将 SAS 数据集中的观测值读入数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!