sas数据操作

set语句:

set语句从一个或多个sas数据集中读取观测值并实现纵向合并,每一个set语句执行时,sas就会读一个观测到pdv中,一个daya步可以有多个set语句,每个set语句可以跟多个sas数据集,多个set语句含有多个数据指针。

set会将输入数据集中的所有观测值和变量读取,除非你中间执行其他步骤

SET<SAS-data-set(s)<(data-set-options(s) )>><options>;

(data-set-options) specifies actions SAS is to take when it reads variables or observations into the program data vector for processing.

Tip:Data set options that apply to a data set list apply to all of the data sets in the list. Data set options specify actions that apply only to the SAS data set with which they appear. They let you perform the following operations:

主要的功能是以下四天,并给出相关例子

renaming variables   ex--> set sashelp.class(rename = (name = name_new));

selecting only the first or last n observations for processing sashelp.class(where =(sex=‘M‘));

dropping variables from processing or from the output data set sashelp.class(drop =name sex);sashelp.class(keep=name sex);

specifying a password for a data set

输出两个数据集

data d1(keep = name) d2(keep = name sex);

  set sashelp.class(keep = name sex);

run;

IN=选项应用

IN本身不是变量,所以不能通过赋值语句获得,IN=的最大作用是标识不同的数据集  

data one;
    input x y$;
    cards;
    1 a
    2 b
    ;
run;
data two;
    input x z$;
    cards;
    3 c
    2 d
    ;
run;

data me;
    set one(in=ina)two(in=inb);
    if ina=1 then flag=1;else flag=0;
run;

res:

 

data me;
 set sashelp.class(firstobs=3 obs=6);   /*读取第三到第六个变量*/
run;

*获取数据集中的总观测数;

data me(keep = total);
 set sashelp.Slkwxl nobs=total_obs;   *if 0 then  set sashelp.Slkwxl nobs=total_obs;改进语句,因为sas是先编译再执行,所以可以选择不执行,只获取编译的信息就足够了
 total = total_obs;
 output;
 stop;
run;

1:程序编译时首先读nobs=选项,该选项在头文件中,nobs=total_obs将总观测数传给临时变量total_obs

2:pdv读入数据集,并把所有变量放入pdv。

。。。。省略

POINT=选项 取指定的一条观测

data me;
 n=3;
 set sashelp.class point=n;

output;

do n=3,6,10;

set sashelp.class point=n;

output;*获取多个指定行的观测;

end;

set sashelp.class nobs = last point=last;
output; *获取最后一行观测值;
 stop;
run;

point=n对应的是变量,不能直接赋值数字省略stop后会让程序进入死循环,不用stop语句sas无法判断该数据指针是否指向了最后一条观测,从而会陷入死循环。如果不用output,会得不到数据集,point和stop一般是连在一起使用

_N_的使用

data d1 d2;

set sashelp.class;

 if _n_ le 10 then output d1;

else output d2;

run;

set读取序列数据集合的一些注意事项:

    set goods1:;*读取所有以good1开头的文件,比如goods12 goods13;
    set sales1-sales4; set sales1 sales2 sales3 sales4;*这两条语句等价;
    /*
    set sales1-sales99; *合法;
    set sales001-sales99; *不合法,如果以0开头,那么后面的文件的数字要比前面的文件的数值的位数多,至少是相等;
    */
    set cost1-cost4 cost2: cost33-37; *可行;

    /* these two lines are the same */
    set sales1 - sales4;
    set ‘sales1‘n - ‘sales4‘n;

    /* blanks in these statements will cause errors */
    set sales 1 - sales 4;
    set ‘sales 1‘n - ‘sales 4‘n;
    /* trailing blanks in this statement will be ignored */
    set ‘sales1   ‘n - ‘sales4   ‘n;

sas数据操作

时间: 2024-08-10 19:04:26

sas数据操作的相关文章

sas数据操作-2

By语句 By语句用于规定分组变量,控制set,merge,update或modify语句 官方说明: BY<DESCENDING> variable-1<...<DESCENDING>variable-n> <NOTSORTED> ; specifies the variable that the procedure uses to form BY groups. You can specify more than one variable. By def

sas数据操作-3

希望有疑问的朋友提出问题,大家一起学习进步,以后我也会多多的写自己的例子 update语句 UPDATE master-data-set<(data-set-options)> transaction-data-set<(data-set-options)> <END=variable> <UPDATEMODE= MISSINGCHECK | NOMISSINGCHECK>; BY by-variable; TIPS: 1:后面只能跟两个数据集,且一定要和b

作业一 统计软件简介与数据操作

spss软件 所属类别 : 软件 SPSS(Statistical Product and Service Solutions),"统计产品与服务解决方案"软件.最初软件全称为"社会科学"(SolutionsStatistical Package for the Social Sciences),但是随着SPSS产品服务领域的扩大和服务深度的增加,SPSS公司已于2000年正式将英文全称更改为"统计产品与服务解决方案",标志着SPSS的战略方向正

包婷婷 (201550484)作业一 统计软件简介与数据操作

SPSS(Statistical Product and Service Solutions),"统计产品与服务解决方案"软件.最初软件全称为"(SolutionsStatistical Package for the Social Sciences),但是随着SPSS产品服务领域的扩大和服务深度的增加,SPSS公司已于2000年正式将英文全称更改为"统计产品与服务解决方案",标志着SPSS的战略方向正在做出重大调整.为IBM公司推出的一系列用于统计学分析

郭佳庆(201551296)第一次作业:统计软件简介与数据操作

一.SPSS 1.基本信息 SPSS(Statistical Product and Service Solutions),"统计产品与服务解决方案"软件.最初软件全称为"社会科学软件包"(SolutionsStatistical Package for the Social Sciences),但是随着SPSS产品服务领域的扩大和服务深度的增加,SPSS公司已于2000年正式将英文全称更改为"统计产品与服务解决方案",标志着SPSS的战略方向正

计算机系统之汇编---IA32处理器数据格式及数据操作

计算机系统之汇编---IA32处理器数据格式及数据操作 IA32数据格式: Intel用术语"字"表示16位数据类型,因此,称32位数为"双字",称64位数为"四字". Char*这里指的是所有指针类型,注意:c语言新增加的long long是八字节,但是硬件IA32不支持这个类型. 寄存器(8个32位的寄存器,均以%e开头) %eax.%ecx.%edx:调用者保存(数据)寄存器,当过程p调用q,q可以覆盖这些寄存器,但是不会改变p中的数据.

Cocos数据篇[3.4](3) ——XML数据操作

[唠叨] XML 即 可扩展标记语言,在游戏开发中,常用于保存游戏数据信息,如最高分.游戏等级等信息,和描述一些资源等. 加载动画的plist文件.瓦片地图编辑器到处的地图格式tmx文件,实际上都是特定格式的xml文件. 另外 UserDefault 单例类保存的数据,也是存储在xml文件中的. Cocos2d-x 已经加入了 tinyxml2库 用于xml的解析.3.x版本位于external/tinyxml2下. 本节要介绍的就是:如何使用 tinyxml2库 来操作处理xml文件. [参考

Redis数据操作--字符串

| 储存文字,储存数字(整数,浮点数),二进制数 |  字符串操作 -- 设置字符串     set key value     # 如果字符串键key已经存在,     那么使用新值覆盖原来的旧值 -- 获取字符串     get key     # 返回字符串键key储存的值 -- 仅在键不存在的情况下进行设置     setnx key value     # 仅在键key不存在的情况下,将键key的值设置为value,     效果和set key value NX一样.NX的意思为"N

SQL语言-----数据操作

数据操作 增加数据,insert into 标准格式 insert into 表名 (字段的列表)value(数据列表): 使用set insert into 表名 set 字段1=值,2.....: 从其他数据表取数据插入 insert into 表名 (字段列表)select; 和insert into一样也是分在种,标准写法,set语法,从其它表取数据 标准方式 replace into 表名 (字段的列表) values (数据列表) 使用set: replace into 表名 set