楼主: Frank233
5074 3

[实际应用] SAS编程高手必看的25个技巧 [推广有奖]

  • 3关注
  • 20粉丝

教授

43%

还不是VIP/贵宾

-

威望
1
论坛币
-203418 个
通用积分
1202.1636
学术水平
43 点
热心指数
68 点
信用等级
43 点
经验
33824 点
帖子
597
精华
0
在线时间
1278 小时
注册时间
2015-6-30
最后登录
2022-1-6

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
  
    CDA就业学院:
cda.pinggu.org/jy.html


      1
After running a SAS programimmediately review the SAS log for noteswarningsand error messagesAvoid turning off SAS System options that turn off SAS log notesmessagesand warnings
  运行完SAS代码,立即查看日志文件。
  2Turn on the SOURCE2 SAS System option to display included source code on the logBest practice coding techniques should mandate inclusion and display of any and all information that is available during a SAS session
  打开SOURCE2SAS系统选项。这里有个讲究,一般提交SAS代码有两种方式,一是在SAS的编辑器里编写或者打开,然后执行,源代码在不在日志文件出现由系统选项SOURCE决定,SOURCE的默认值是1,二就是用如%include “testsas”语句提交,这时源代码testsas是否在日志里出现由系统选项SOURCE2决定,它的默认值是0。打开SOURCE2SAS系统选项的方法是,打开Tools-Options-System,在Options-log and procedure output control-SAS log下,找到SOURCE2,把它的Value改成1
  3Considering procedures like PROC SQL and PROC REPORT for code simplificationBecause multiple processes can be frequently accomplished in a single procedure stepI/O may be reduced
  为了简化代码,考虑使用proc sql或者proc report。作者是一个SAS畅销书PROC SQLBeyond the Basics Using SAS的作者。SAS是一个庞大的工具箱,有多种编程方式。选择应该是基于实用主义原则的,哪个好用用哪个。
  4When a DATA step or PROC can do the same jobconsider using procedures whenever possibleProcedures are tried-and-proven throughout the world's SAS installationstesting requirements is considerably less
  如果data步和proc步能完成同一个任务,尽量用proc步。SAS内置的proc步是经过研发人员多次测试通过的,一般会比我们写的强健一些。
  5Create user-defined format libraries to store formatted values in one placeUser-defined format libraries have the added advantage of making programs easier to maintain since formatted data values are not hard coded
  在同一个地方建库,存放所有自定义的格式化数据。
  6Include RUN statements at the end of each DATA or PROC step to separate step boundariesto print benchmark statistics on the SAS log immediately following each step
  在每一个data步和proc步之后加上run语句。
  7Document programs and routines with commentsIn addition to the value associated with explaining program logiccomments should provide important information about complex code and logic conditions in a programThis helps to document important program processes as well as minimizes the learning curve associated with program maintenance and enhancement for other users
  养成代码加注释的习惯,尤其是在代码算法方面。
  8Assign descriptive and meaningful variable namesBesides improving the readability of program codeit serves an important element in the form of documentation
  养成良好的变量命名习惯。选用一目了然的名字,而不是如var1var2
  9Construct program header information to serve as program documentation for all programsThe following example illustrates the type of information that can be added so others have a useful documented history
  软件项目管理,好像只跟C++、Java有关,其实,在一个大的SAS开发或应用系统里,项目管理的实施同样重要。这里说的是代码归档的事(documentation)。前面第7条说的代码加注属于documentation的尝试之一,program header(文件注释头)是每份源代码的开头,写的对其他程序员或客户看的指导性的注释,我们常见的花盒子注释就是。一个叫A Programming Development Environment for SAS Programs的文档,可以参考这里。
  10Simplify complex code and operations into smallermore manageable partsBy splitting complex code into two or more programming statementsa program becomes easier to read as well as more maintainable
  把复杂的代码分解成易于管理的小块(blocks)。
  11Specify SAS data set names when invoking procedures to help improve documentation efforts as well as preventing an incorrect data set from being processed
  在调用proc步时,指定要引用的数据,用proc print dataa;而不是proc print;。
  12Utilize macros for redundant code and enable autocall processing by specifying the MAUTOSOURCE system option
  用宏(macro)来管理你的代码。打开MAUTOSOURCE系统选项以便自动调用宏(这是默认的)。
  13Create macro libraries to store common macro routines in one place
  在同一个地方建库,存放所有类似的宏文件。
  14Create permanent libraries containing information from dailyweeklymonthlyquarterlyand annual runsThe type of libraries consists of scriptsSAS programsSAS logsoutput listsand documentation of instructions for others to follow
  为每天、每周、每月、每季度和每年都要运行的例行代码,分别建立永久性的库,存放相关的信息。
  15Create views based on user input to simplify and streamline redundantcomplex and/or burdensome tasksConsider creating views in a central view library to support maintenance and documentation requirements
  视图是数据库里的概念。简单地说,比如,你用十行SQL代码完成了一次查询,这个查询结果是你老板(客户)感兴趣的。以后你老板想要看这个查询结果,你可以让他每次都写或运行这个十行代码,或者,你把这次查询的结果做成一个虚拟的表——说是虚拟的,因为数据库里并不真正存在这张表,存在的只是这十行SQL脚本;说是表,是因为运行这个脚本时表就会动态生成。这个虚拟的表,就叫做视图。现在你把中堆东西做成了一个视图,你老板想要这个结果,只需要写一句“视图,阿里巴巴”。视图有很多好处,这里是可以简化老板对数据的理解,同时简化他们的操作。
  16Code for unknown data valuesThis will prevent unassigned or null data values from falling through logic conditions
  对未知的数据值,用编码表示,如99999999之类。如果是空值,可能会引起一些预料不到的逻辑错误。
  17Store informatsformatsand labels with the SAS data sets that use themInformatsformatsand labels should be stored with important SAS data sets to minimize processing timeAn important reason for using this technique is that many popular procedures use stored formats and labels as they produce outputeliminating the need to assign them in each individual stepThis provides added incentives and value for programmers and usersespecially since reporting requirements are usually time critical
  把数据的描述性部分(descriptor portion)如informatsformatsand labels跟数据存储在一起。
  18Construct conditions that would render data unusable and abort or endthe programThis prevents unwanted or harmful data from being processed or written to a data set
  写一段条件语句,使得数据不能够被随意改写。(这段我还要好好琢磨一下)
  19Test program code using “complete”test data particularly if the data set is small or represents a random sample of a large data set
  测试代码时,使用所有的测试数据,特别是这些测试数据本身很小,或者它们就是总体数据的一个很好的样本。
  20Set OBS0 to test syntax and compile time errors without the risk of executing any observations through a DATA or PROC step
  测试代码的语法错误时,使用obs0这个选项。
  21Use the PROC SQL VALIDATE clause to test syntax and compile time errors in PROC SQL code
  PROC SQL时,用VALIDATE这个选项来指示语法错误。
  22Specify the NOREPLACE system option to prevent permanent SAS data sets from accidentally being overwritten while writing or testing a program
  为了防止永久逻辑库里的数据文件被改写或者覆盖,使用NOREPLACE这个系统选项。具体做法是把系统选项REPLACE的值改为0。做练习时这个选项要慎用。
  23Take advantage of procedures that summarize large amounts of data by saving and using the results in order to avoid reading a large data set again
  为了避免重复读入大型的数据,利用一些proc步,它们可以通过保存一些处理过的结果来概况数据。
  24Add options that are frequently used into the SAS configuration fileThis eliminates the time and keystrokes necessary to enter them during a SAS session
  在SAS的配置文件里添加一些你常用的选项。SAS的配置文件就是sas root下的那个SASV9CFG,以SAS 9为例。这里你可以找到更多相关的信息。
  25Add statements that are frequently used into the SAS autoexec fileThis eliminates the time and keystrokes necessary to enter them during a SAS session
  在SAS的自动运行文件AUTOEXECSAS
里加入一些个性化的语句。不熟就不要尝试了.

SAS数据统计分析师认证培训


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:SAS编程 编程高手 Requirements Installation observations techniques available practice included 编程高手

已有 2 人评分经验 学术水平 热心指数 信用等级 收起 理由
eijuhz + 20 精彩帖子
Tigflanker + 1 + 2 + 3 又仔细看了下,觉得很不错。

总评分: 经验 + 20  学术水平 + 1  热心指数 + 2  信用等级 + 3   查看全部评分


CDA数据分析交流群 217748971
沙发
zhengbo8 发表于 2015-9-25 20:03:29 |只看作者 |坛友微信交流群
都是很实用的tips或习惯~

使用道具

藤椅
Enginx 发表于 2015-9-29 14:10:36 来自手机 |只看作者 |坛友微信交流群
实用指导指南

使用道具

板凳
文安少年 发表于 2019-11-18 17:50:52 |只看作者 |坛友微信交流群
赞赞赞,写的很好

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-27 11:10