使用 sas 获取数据步骤中的行号 [英] get a the row number in a data step using sas

查看:63
本文介绍了使用 sas 获取数据步骤中的行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法做一个过度分区来获取sas上的行号?在 sql 中,我想:

Is there a way to get to do a over partition to get the row number on sas? In sql I would go like:

  Select region,company, ROW_NUMBER()  OVER(PARTITION BY region ORDER BY Name)
    From companyData;

我想最好在数据集中这样做

I want to do this in a data set preferably

推荐答案

您可以使用 by 语句轻松地在数据步骤中执行此操作,它和执行运行总和 :

You can do that in a data step easily by using the by statement, it and the do a running sum :

proc sort data=myData;按地区名称;运行;

Data myData;
Set myData;
By company;
if first. company then n=1;
   else n+1;
run;

还要确保您可以使用内置功能的所有 obs:

Also to ennmuarete all the obs you can use the built in features:

DATA COMPANYDATA;
SET COMPANYDATA;
ROW_NUM=_N_;    
RUN;

正如 Joe 提到的,您可能希望根据您在该分组中获得的 obs 数量来设置 row_num 的格式.

As Joe mentioned you might want to set the format for your row_num depending on how much obs you would get within that grouping.

这篇关于使用 sas 获取数据步骤中的行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆