如何使用select创建一个数值降序的宏数组

问题描述 投票:0回答:2

我使用select来创建一个宏数组

proc sql;

select numValue into:num_value separated by ' ' from tableA;

quit;



%put %scan(num_value,1);

但是,宏num_value中的值没有按原始顺序(从小到大)排列它们的数值。

那么我怎么能根据它们的索引来确定它们的值是下降还是上升,或者宏数组与原始表的顺序相同。

谢谢!

sas
2个回答
1
投票

如果我正确理解你的问题,你想在宏变量中订购值,你可以这样做:

proc sql;
   select height into:height from sashelp.class order by height;
quit;

%put &height;

1
投票

代码:下面按降序排列的值,如果未指定,则默认顺序为升序。

proc sql;
   select height into:height separated by ' ' from sashelp.class order by height desc;
quit;

%put &height;

日志:

72 69 67 66.5 66.5 65.3 64.8 64.3 63.5 62.8 62.5 62.5 59.8 59 57.5 57.3 56.5 56.3 51.3

输出:

SQL output

© www.soinside.com 2019 - 2024. All rights reserved.