SAS 我可以逆向进行 sas 过程观察吗

发布于 2024-07-23 01:34:18 字数 83 浏览 5 评论 0原文

我知道Sas在处理时从数据集顶部的观察开始,然后继续进行下一个直到到达底部观察,但是有没有一种简单的方法可以让sas首先处理底部观察,然后再处理到顶部?

I know that Sas starts with the observation at the top of a dataset when processing and proceeds to the next until it reaches the bottom observation, but is there an easy way to make sas process the bottom observation first and then work its way to the top?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

久随 2024-07-30 01:34:18

您可以使用nobspoint向后处理它,而无需执行任何中间步骤。 下面是一个示例:

data backwards;
  do k= nobs to 1 by -1;
   set sashelp.class nobs = nobs point=k;
   output;
  end;
  stop;
run;
proc print data=sashelp.class;run;
proc print data=backwards;run;

请参阅此 pdf 的第 2 页了解所有有趣的详细信息。

You can use nobs and point to process it backwards without having to do any intermediate steps. Here's an example:

data backwards;
  do k= nobs to 1 by -1;
   set sashelp.class nobs = nobs point=k;
   output;
  end;
  stop;
run;
proc print data=sashelp.class;run;
proc print data=backwards;run;

See page 2 of this pdf for all the juicy details.

z祗昰~ 2024-07-30 01:34:18

您当然可以将数据更改为相反的顺序,然后从上到下处理。 将一个变量添加到充当索引的数据集。然后按该变量对数据集进行降序排序。

data work.myData ;
 set work.myData ;
 indx = _n_ ;
run ;

proc sort data=work.myData ;
 by descending indx ;
run ;

You certainly can change your data to be in reverse order, then process top down. Add a variable to the data set which acts as an index..then sort the data set descending by that variable.

data work.myData ;
 set work.myData ;
 indx = _n_ ;
run ;

proc sort data=work.myData ;
 by descending indx ;
run ;
日暮斜阳 2024-07-30 01:34:18

您可以使用 PROC SQL 在一步中翻转观察顺序:

proc sql;
   create table work.cars as
   select *
   from sashelp.cars
   order by monotonic() desc;
quit;

这里的关键是order by monotonic() desc,它翻译为“按观察值降序排序”。

或者,您可以创建一个视图(而不是创建表),该视图将引用原始表,但以相反的观察编号顺序:

proc sql;
   create view work.cars_rev as
   select *
   from sashelp.cars
   order by monotonic() desc;
quit;

You can flip your observations order in a single step using PROC SQL:

proc sql;
   create table work.cars as
   select *
   from sashelp.cars
   order by monotonic() desc;
quit;

The key here is order by monotonic() desc which translates as "sort by descending observation numbers".

Alternatively, you can create a view (instead of creating a table) which will refer to the original table, but in a reverse observation number order:

proc sql;
   create view work.cars_rev as
   select *
   from sashelp.cars
   order by monotonic() desc;
quit;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文