SlideShare a Scribd company logo
1 of 26
統計學與資料分析
SAS實習課 11/29
改進program及output的方法
Title
Data statement
System options
改進program及output的方法
Title
Data statement
System options
Comment Statement

    註解、修改程式
*message;


/*message*/
「*message;」
CODE
1.   data a;
                          OUTPUT
2.   input age sex $;
3.   datalines;
4.   7M
5.   2 F
6.   5M
7.   ;
8.   proc print; *test;
9.   Run;
「*message;」限制:
CODE
1.   data a;
2.   input *test’;’ ; age sex $;   不能包含其他的
3.   datalines;
4.   7M                            分號「;」,
5.   2 F                           或不成對的引號
6.   5M
7.   ;                             「‘」、「“」
8.   proc print;
9.   Run;
「*message;」限制:
CODE
1.   data a;            LOG
2.   input *test’;’ ;   ERROR: The name test’ is not a valid SAS
                        name.
     age sex $;         ERROR 22-322: Syntax error, expecting
3.   datalines;         one of the following: a
                        name, arrayname, #, (, +, /, //, ;, @, @@.
4.   7M
                        ERROR 180-322: Statement is not valid or
5.   2 F                it is used out of proper order.
6.   5M
                        ERROR 202-322: The option or parameter
7.   ;                  is not recognized and will be ignored.
8.   proc print;
9.   Run;
「/*message*/」
CODE
1.   data a;
                            OUTPUT
2.   input age sex $;
3.   datalines;
4.   7M
5.   2 F
6.   5M
7.   ;
8.   proc print; /*test*/
9.   Run;
「/*message*/」

  相較於「*message;」,
  「/*message*/」能使SAS忽略所有的內容物
「*message;」vs. 「/*message*/」

CODE           CODE
TITLE Statement

TITLE <n> <'text' | "text">;
TITLE Statement

CODE                           OUTPUT
1.    data a;
2.    input age sex $;
3.    datalines;
4.    7M
5.    2 F
6.    5M
7.    ;
8.    proc print;
9.    title1 "Title: Data";
10.   title2 "Title: Age and
      sex";
TITLE Statement
CODE                          OUTPUT
1.   proc print;
2.   title1 "Title: Data";
3.   title2 "Title: Age and
     sex";

4.   proc means;              OUTPUT
5.   var age;
6.   Run;
TITLE Statement
CODE
1.   proc print;
2.   title1 "Title: Data";
3.   title2 "Title: Age and
     sex";

4.   proc means;
5.   var age;                       OUTPUT
6.   Title;
7.   Run;
Data statement
Data statement

Data;

Data XXXX;

Data _null_; /*不建立dataset*/
Data statement
                     CODE
                    1.   data a (keep=id age);
Data a (keep=var)   2.   input id age sex $;
                    3.   datalines;
Data a (drop=var)   4.   11 7 M
                    5.   12 2 F
                    6.   13 5 M
                    7.   ;

                    8.   proc print;
                    9.   run;
Data statement
                  CODE
OUTPUT           1.   data a (keep=id age);
                 2.   input id age sex $;
                 3.   datalines;
                 4.   11 7 M
                 5.   12 2 F
                 6.   13 5 M
                 7.   ;

                 8.   proc print;
                 9.   run;
Data statement

Data New (firstobs=20);

Data New (obs=1000);

Data New (firstobs=20,obs=1000);
Data statement
CODE
1.    data a;
2.    input id age sex $;
                            OUTPUT
3.    datalines;
4.    11 7 M
5.    12 2 F
6.    13 5 M
7.    ;
8.    data new;
9.     set a (obs=2);
10.   proc print
      data=new;
11.   id id;
12.   run;
Data statement
CODE
1.    data a;
2.    input id age sex $;    OUTPUT
3.    datalines;
4.    11 7 M
5.    12 2 F
6.    13 5 M
7.    ;
8.    data new;
9.     set a (firstobs=2);
10.   proc print
      data=new;
11.   id id;
12.   run;
CODE            Data statement
1.    data a;
2.    input id age sex $;
3.    datalines;            OUTPUT
4.    11 7 M
5.    12 2 F
6.    13 5 M
7.    14 4 F
8.    ;
9.    data new;
10.    set a
      (firstobs=2,obs=3);
11.   proc print
      data=new;
12.   id id;
13.   run;
System Options

                   OPTIONS option(s);
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/view
er.htm#a000309878.htm
System Options
                 (for output)
 Center/nocenter                            Pagesize= n
  Date/nodate                                 Missing=
Number/nonumber                              Firstobs=n
  Lable/nolable                                Obs=n
   Linesize=n

http://www.ats.ucla.edu/stat/sas/modules/options.htm
option nodate
CODE
1.    option nodate;
2.    data a;
3.    input id age sex $;
4.    datalines;
5.    11 7 M
6.    12 2 F
7.    13 5 M
8.    14 . F
9.    ;
10.   proc print;
11.   run;

More Related Content

Similar to 1129 sas實習課

ESNext for humans - LvivJS 16 August 2014
ESNext for humans - LvivJS 16 August 2014ESNext for humans - LvivJS 16 August 2014
ESNext for humans - LvivJS 16 August 2014Jan Jongboom
 
SAS cheat sheet
SAS cheat sheetSAS cheat sheet
SAS cheat sheetAli Ajouz
 
This is my code but not complete, please complete my.pdf
This is my code but not complete, please complete my.pdfThis is my code but not complete, please complete my.pdf
This is my code but not complete, please complete my.pdffashionbigchennai
 
OWASP Top 10 - DrupalCon Amsterdam 2019
OWASP Top 10 - DrupalCon Amsterdam 2019OWASP Top 10 - DrupalCon Amsterdam 2019
OWASP Top 10 - DrupalCon Amsterdam 2019Ayesh Karunaratne
 
Steps to Easier SAS Code Maintenance
Steps to Easier SAS Code MaintenanceSteps to Easier SAS Code Maintenance
Steps to Easier SAS Code Maintenancejrhampt
 
Developing Applications with MySQL and Java for beginners
Developing Applications with MySQL and Java for beginnersDeveloping Applications with MySQL and Java for beginners
Developing Applications with MySQL and Java for beginnersSaeid Zebardast
 

Similar to 1129 sas實習課 (10)

ESNext for humans - LvivJS 16 August 2014
ESNext for humans - LvivJS 16 August 2014ESNext for humans - LvivJS 16 August 2014
ESNext for humans - LvivJS 16 August 2014
 
SAS cheat sheet
SAS cheat sheetSAS cheat sheet
SAS cheat sheet
 
This is my code but not complete, please complete my.pdf
This is my code but not complete, please complete my.pdfThis is my code but not complete, please complete my.pdf
This is my code but not complete, please complete my.pdf
 
Sas classes in mumbai
Sas classes in mumbaiSas classes in mumbai
Sas classes in mumbai
 
OWASP Top 10 - DrupalCon Amsterdam 2019
OWASP Top 10 - DrupalCon Amsterdam 2019OWASP Top 10 - DrupalCon Amsterdam 2019
OWASP Top 10 - DrupalCon Amsterdam 2019
 
Intro to Ember.JS 2016
Intro to Ember.JS 2016Intro to Ember.JS 2016
Intro to Ember.JS 2016
 
Steps to Easier SAS Code Maintenance
Steps to Easier SAS Code MaintenanceSteps to Easier SAS Code Maintenance
Steps to Easier SAS Code Maintenance
 
SAS Internal Training
SAS Internal TrainingSAS Internal Training
SAS Internal Training
 
Developing Applications with MySQL and Java for beginners
Developing Applications with MySQL and Java for beginnersDeveloping Applications with MySQL and Java for beginners
Developing Applications with MySQL and Java for beginners
 
1027實習
1027實習1027實習
1027實習
 

More from WenSheng Chang (15)

futureNo52
futureNo52futureNo52
futureNo52
 
Sas plot
Sas plotSas plot
Sas plot
 
Sas reg multi
Sas reg multiSas reg multi
Sas reg multi
 
Sas reg simple
Sas reg simpleSas reg simple
Sas reg simple
 
Sas corr
Sas corrSas corr
Sas corr
 
Sas tutorial 1018
Sas tutorial 1018Sas tutorial 1018
Sas tutorial 1018
 
Sas tutorial 0524
Sas tutorial 0524Sas tutorial 0524
Sas tutorial 0524
 
Sas tutorial glm2
Sas tutorial glm2Sas tutorial glm2
Sas tutorial glm2
 
Sas tutorial glm1
Sas tutorial glm1Sas tutorial glm1
Sas tutorial glm1
 
Regression ci
Regression ciRegression ci
Regression ci
 
SAS 0412
SAS 0412SAS 0412
SAS 0412
 
Sas tutorial 0308
Sas tutorial 0308Sas tutorial 0308
Sas tutorial 0308
 
Sas tutorial 0308
Sas tutorial 0308Sas tutorial 0308
Sas tutorial 0308
 
0925 sas實習課
0925 sas實習課0925 sas實習課
0925 sas實習課
 
Science p79 -- polished
Science p79 -- polishedScience p79 -- polished
Science p79 -- polished
 

1129 sas實習課