[英]How to fill column using values in 2 other columns in PROC SQL / SAS code in SAS Enterprise Guide?
[英]How to select only char variables with PROC SQL in SAS Enterprise Guide?
我有以下代碼:
PROC SQL INOBS=10 OUTOBS=10;
CREATE TABLE WORK.FREQUENCY_&ColumnName AS
SELECT t1.&ColumnName,
(COUNT(t1.&ColumnName)) AS COUNT_of_&ColumnName
FROM &libname..&tblname t1
GROUP BY t1.&ColumnName
ORDER BY COUNT_of_&ColumnName DESC;
此代碼有效,但使用此代碼我選擇了所有類型的變量,但是只有當變量是 CHAR 時,我才想 select。
有沒有辦法用一個簡單的 where clausule 創建這個條件? 還是我需要創建一個“如果條件”? 如果是,我該如何創建它?
謝謝你!
我現在沒有可用的 SAS 安裝,但此代碼應該可以工作
data _null_;
/*
The relevant columns are probably named differently;
Check the table sashelp.vcolumn what the values in COLTYPE for character variables actually are
Don't know exactly out of my head
*/
set sashelp.vcolumn(where=(MEMNAME eq 'MY_TABLE' and COLTYPE in ('CHAR', 'VARCHAR'))) end=eof;
attrib COLNAMES format=$1000.;
retain COLNAMES;
/*
the following two lines concatenate all extracted column names;
choose one of the two
*/
/*concatenate all variable names in a string using || operator*/
COLNAMES = compbl(COLNAMES) || ', ' || compbl(COLNAME);
/*or via function catx*/
colnames=catx(', ',colnames,colname);
/*define a macro variable to hold all determined columns*/
if eof then do;
call symput('M_COLNAMES', compbl(COLNAMES));
end;
run;
/*print all found columns*/
%put Character columns: &M_COLNAMES.;
然后,您可以在 select 語句中使用宏變量 M_COLNAMES。 這應該讓您了解如何做到這一點。
不要猶豫,提出進一步的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.