简体   繁体   English

如何在 SAS 企业指南中仅使用 PROC SQL select char 变量?

[英]How to select only char variables with PROC SQL in SAS Enterprise Guide?

I have the following code:我有以下代码:

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;

This code is working but with this code I am selecting all types of variables, however I would like to select only if a variable is CHAR.此代码有效,但使用此代码我选择了所有类型的变量,但是只有当变量是 CHAR 时,我才想 select。

Is there a way that I create this condition with a simple where clausule?有没有办法用一个简单的 where clausule 创建这个条件? Or do I need to create a 'if condition'?还是我需要创建一个“如果条件”? If yes, how can I create it?如果是,我该如何创建它?

Thank You!谢谢你!

I don't have a SAS installation available right now but this code should work我现在没有可用的 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.;

You can then use the macro variable M_COLNAMES in your select statement.然后,您可以在 select 语句中使用宏变量 M_COLNAMES。 This should give you an idea how you can do this.这应该让您了解如何做到这一点。

Don't hesitate to ask further questions.不要犹豫,提出进一步的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 SAS 企业指南中 PROC SQL / SAS 代码中的其他 2 列中的值填充列? - How to fill column using values in 2 other columns in PROC SQL / SAS code in SAS Enterprise Guide? SAS Enterprise Guide proc sql - 使用 when 语句包含在内 - SAS Enterprise Guide proc sql - using when statements inclusively 如何计算在 SAS 企业指南中的 PROC SQL 中定义 ID 的某个值出现了多少次? - How to count how many time some value appeard with defined ID in PROC SQL in SAS Enterprise Guide? 如何在 PROC SQL 中使用 SAS 企业指南中每月值的总和创建新列? - How to create new column in PROC SQL with sum of values per month in SAS enterprise Guide? 如何在 SAS 企业指南中的 PROC SQL 的两列之间创建标志 0/1 通知是否在 4 个月内更改? - How to create flag 0/1 inform whether was changed or not during 4 months between two columns in PROC SQL in SAS Enterprise Guide? 如何在 SAS 企业指南中的 PROC SQL 中创建标志通知 ID 上的两列是否有变化? - How to create flag inform whether was some change in two columns on ID in PROC SQL in SAS Enterprise Guide? SAS企业指南/ SQL性能 - SAS Enterprise Guide / SQL Performance 如何在 SAS 企业指南中的 PROC SQL 的某些日期中的 2 列之间更改值来创建 0/1 标志? - How to create 0/1 flag witch infrom whether values were changed between 2 column in some dates in PROC SQL in SAS Enterprise Guide? 使用SAS中的PROC SQL选择变量范围 - Select range of variables with PROC SQL in SAS 如何提高SAS Enterprise Guide 4的性能 - How to improve the performance of SAS Enterprise Guide 4
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM