簡體   English   中英

proc sql/SAS:創建一個案例,當一列是= this and row = that then col=1 row=2

[英]proc sql/SAS: Create a case when a column is = this and row =that then col=1 row=2

在此處輸入圖像描述

這就是我的數據的樣子在此處輸入圖像描述

我想打印出一個時間

藍色和紅色相同,然后打印 col=010 和 row=200,我想對 64 個觀察結果執行此操作。

我對一個單元格的嘗試是:

proc sql;
create table ____matrix as
select *,
(case
when 'red'=' ' and 'blue'=' ' then col='0010' and row='0110'
when ....
uptil [64 times.}
else .
end)
from final
;quit
;

我也試過

proc sql;
create table ____matrix as
select *,
(case
when 'red'='blue' then col='0010' and row='0110'
when ....
uptil [64 times.}
else .
end)
from final
;quit
;

但它不工作。 col 和 row btw 是一個字符,rest 是數字數據

我不確定目標實際上是什么,輸入數據看起來很奇怪。 我可以假設您有藍色、紅色、綠色等數字列,並且您希望根據它們的值填充列 col 和 row。 您的 sql 代碼可能看起來是這樣的:

proc sql;
create table ____matrix as
select *,
(case
when red=blue then '0010'
when red=green then '0020' 
/*uptil [64 times.}*/
else ''
end) as col,
(case
when red=blue then '0110'
when red=green then '0220' 
/*uptil [64 times.}*/
else ''
end) as row
from final
;
quit;

使用數據步驟而不是 proc sql; 會幫助你使代碼更容易。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM