使用SAS中的PROC转置进行列排序

时间:2017-07-07 20:25:38

标签: sas

我使用下面提到的代码来获取proc转置后动态排序的列。我为这个解决方案提供了很多解决方案。但是现在我运行

时出错了
data work.AB ;
input name $ class $ dt $ gpa $;
datalines;
JOHN 1 201607 C-
JOHN 1 201608 C+
JOHN 1 201702 B-
JOHN 2 201608 A
NICK 1 201608 A
NICK 1 201707 A
MIKE 2 201608 B
MIKE 2 201607 B
MIKE 2 201707 B+
MIKE 2 201702 B
BOB 3 201702 D
BOB 3 201607 C
BOB 3 201707 C
;
proc sort data=work.AB;
by NAME ClASS dt;
run;

PROC TRANSPOSE DATA = AB OUT = ABC(drop=_name_) ;
BY nAME cLASS; 
VAR GPA;
ID dt; 
RUN ;

proc sql ;
create table test as 
select name into : list separated by ' '
from dictionary.columns
where libname='WORK' and memname='ABC'
order by input(substr(name,anydigit(name)),best32.)
;
quit;

%put &list;

data want;
retain &list;
set ABC;
run;

我得到的错误是

22 GOPTIONS ACCESSIBLE;
WARNING: Apparent symbolic reference LIST not resolved.
23 %put &list;
&list

24 data want;
25 retain &list;
_
22
200
WARNING: Apparent symbolic reference LIST not resolved.

ERROR 22-322: Syntax error, expecting one of the following: a name, ;, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_.
ERROR 200-322: The symbol is not recognized and will be ignored.

26 set ABC;
27 run;

请建议。

1 个答案:

答案 0 :(得分:0)

您不能将同一SELECT语句中的值放入数据集和宏变量中。从SQL代码中删除create table test as

您还可以通过将查询更改为:

来取消某些警告
proc sql noprint ;
select case when (not anydigit(name)) then -1
            else input(substr(name,anydigit(name)),?32.)
       end as order
     , name
  into :list
     , :list separated by ' '
from dictionary.columns
where libname='WORK' and memname='ABC'
order by 1
;
quit;

%put &list;