- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个如下所示的数据集。每行是一个不同的观察值,其值从 1 到 x(在本例中为 x=3)。我想创建一个包含原始信息的数据集,但还有四个附加列(用于数据集中存在的 Bin 的四个值)。如果该行中存在任何 1,则列 freq_Bin_1 的值将为 1,否则为缺失。如果存在任何 2,则列 freq_Bin_2 将为 1,等等。
原始数据集中的 Bins 数量和列数可能会有所不同。
data have;
input Bin_1 Bin_2 Bin_3;
cards;
1 . .
3 . .
1 1 .
3 2 1
3 4 .
;
run;
这是我想要的输出:
data want_this;
input Bin_1 Bin_2 Bin_3 freq_Bin_1 freq_Bin_2 freq_Bin_3 freq_Bin_4;
cards;
1 . . 1 . . .
3 . . . . 1 .
1 1 . 1 . . .
3 2 1 1 1 1 .
3 4 . . . 1 1
;
run;
我有一个我认为非常接近的数组解决方案,但我不太明白。我也对其他方法持开放态度。
data want;
set have;
array Bins {&max_freq.} Bin:;
array freq_Bin {&num_bin.} freq_Bin_1-freq_Bin_&num_bin.;
do j=1 to dim(Bins);
freq_Bin(j)=.;
end;
do k=1 to dim(freq_Bin);
if Bins(k)=1 then freq_Bin(1)=1;
else if Bins(k)=2 then freq_Bin(2)=1;
else if Bins(k)=3 then freq_Bin(3)=1;
else if Bins(k)=4 then freq_Bin(4)=1;
end;
drop j k;
run;
最佳答案
这应该有效:
data want;
set have;
array Bins{*} Bin:;
array freq_Bin{4};
do k=1 to dim(Bins);
if Bins(k) ne . then freq_Bin(Bins(k))=1;
end;
drop k;
run;
我稍微调整了你的代码,但真正唯一的问题是你需要在尝试使用它来索引数组之前检查 Bins(k)
是否丢失。此外,无需将值初始化为 missing,因为这是默认设置。
关于arrays - 使用 SAS 检查列是否具有指定的特征,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30379652/
有没有办法从 .sas 文件中打开 SAS 数据集进行查看(即在“ViewTable”窗口中)? 最佳答案 我认为这会做你想做的: dm log "vt sashelp.air"; 只需更改 "sas
如何在 SAS 程序中将 sas 数据表 (sas7bdat) 设置为只读? — 即使在 session 之间,该表也必须保持只读状态,尤其是当另一个用户注册该库并尝试写入数据集时。一旦创建了这些表,
如何将 mmddyy 变量转换为 date9 变量?例如,假设我们有以下内容: x = 05/10/2011 我希望 x 的形式为 10May2011。所以我做了以下事情: xnew =
我正在使用以下代码将文本文件导入 SAS: proc import datafile="C:\Users\Desktop\data.txt" out=Indivs dbms=dlm replace;
您好,我有兴趣为我在 SAS 中生成的数据制作一些稍微复杂的自定义格式。我需要它是数字类型。 格式 1 0="-" >0="%" %" 即 0 >>>>>>> - .74 >>>>> 74% -.65
我正在尝试弄清楚如何读取文本文件 (300mb) 中以逗号分隔但数据位于一行中的数据。 数据看起来像这样: a,b,c,d,e,f,g,h,i,j,k,l,m,false,false,true,1,3
我想将 SAS 数据集从 SAS 导出到 FTP。我可以使用以下命令导出 csv 文件(或 txt 文件): %macro export_to_ftp(dsn= ,outfile_name= ); F
这个问题在 SAS forum 上讨论过,与会者最终同意不同意。 问题很简单:SAS 在编译时为所有变量分配一个缺失值UNLESS一个变量出现在sum 语句中(在这种情况下,SAS 在编译时分配了一个
众所周知,SAS需要特别注意句子中的引号。 例如 %let quoted="I'd like to"; data temp; set temp; quoted=""ed"; r
我对 SAS 完全陌生,我很绝望。 所以,我的代码是: DATA abc; INPUT AA BB CC DD EE; CARDS; ; RUN; PROC PRINT DATA = abc; T
我在使用如下所示的数据集时遇到问题。它是不同位置/周的库存计数: data have; input itm location $ week inv; cards; 3 x 1 30 3 x 2
我们需要确定我们现在使用的是什么类型的 SAS(pc SAS 或服务器 SAS)。有什么方法可以找出我们使用的是什么 SAS,是指 PC SAS 还是 SAS Server? 最佳答案 使用“proc
假设我有一个包含 n 行和 p 列的数据集,这样数据集中的每个条目都包含一个实数。我正在寻找一种方法来对每行中的 p 列进行排名。这个排名的输出应该是一个长度 - p 的排名向量,它说明了关系。 所以
我正在尝试打印一个带分隔符的文件,而不必指定所有列。我可以接近,但数字列总是被引用: DATA _NULL_; SET SASHELP.CARS (obs = 5 keep = Make Mode
SAS 软件可以成功读取的最大文件大小是多少。(不考虑硬件限制) 提前致谢。 最佳答案 引用最近播放的电视广告,答案是“无限加 1”。 SAS 在读取操作期间对文件的大小没有任何限制,尽管您可能会遇到
我有一个包含变量 y、x1 和 x2 的数据集。我想找到适合模型的方程式: y = k1*x1c1 + k2 *x2c2 通过找到 k1、c1、k2 和 c2。我如何在 SAS 中执行此操作?具体来说
SAS中是否有用于定义数组中字母序列的简写? 许多语言都具有轻松执行此操作的机制,我想SAS也是如此,尽管我找不到它的引用。 例如,在R中,我可以做 > x x [1] "a" "b" "c" "d
我有两个 SAS 数据集。第一个相对较小,包含唯一的日期和相应的 ID: date dateID 1jan90 10 2jan90 15 3jan90 20 ... 第二个
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
我有一个主要是数值的变量,但是偶尔会有一个字符偷偷进入。因此,变量在 SAS 中存储为字符。我希望能够确定此字符变量中的各个值是否为数字。在知道哪些值是数字哪些是字符后,我想创建一个新的(数字)变量,
我是一名优秀的程序员,十分优秀!