[英]Split a row into multiple rows in SAS enterprise guide
当行上的值是1-5时,我需要帮助将行拆分为多行。 原因是我需要计数1-5才能变成5,而不是1,因为计数是一行。
我有一个ID,值及其所属位置。
作为示例:
ID Value Page
1 1-5 2
我想要的输出是这样的:
ID Value Page
1 1 2
1 2 2
1 3 2
1 4 2
1 5 2
我试过使用IF陈述式
IF bioVerdi='1-5' THEN
DO;
..
END;
所以我不知道在DO之间应该放置什么。 和END;。 有什么线索可以帮助我吗?
您需要遍历范围内的值并OUTPUT
值。 OUTPUT
语句使“数据步骤”将记录写入输出数据集。
data want;
set have;
if bioVerdi = '1-5' then do;
do value=1 to 5;
output;
end;
end;
这是另一个解决方案,其示例示例中的实际值较少限制为“ 1-5”,但适用于格式为“ 1-6”,“ 1-7”,“ 1-100”等的任何值。
*this is the data you gave ;
data have ;
ID = 1 ;
value = '1-5';
page = 2;
run;
data want ;
set have ;
min = scan( value, 1, '-' ) ; * get the 1st word, delimited by a dash ;
max = scan( value, 2, '-' ) ; * get the 2nd word, delimited by a dash ;
/*loop through the values from min to max, and assign each value as the loop iterates to a new column 'NEWVALUE.' Each time the loop iterates through the next value, output a new line */
do newvalue = min to max ;
output ;
end;
/*drop the old variable 'value' so we can rename the newvalue to it in the next step*/
drop value min max;
/*newvalue was a temporary name, so renaming here to keep the original naming structure*/
rename newvalue = value ;
run;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.