How to install sasmarkdown

sasmarkdown

Use an Engine

# knitr::opts_chunk$set(echo = TRUE)
require(SASmarkdown)
## Loading required package: SASmarkdown
## sas, saslog, sashtml, and sashtmllog engines
##    are now ready to use.
saspath <- "C:/Program Files/SASHome/SASFoundation/9.4/sas.exe"
sasopts <- "-nosplash -ls 75"
knitr::opts_chunk$set(engine='sashtml', engine.path=saspath,
                      engine.opts=sasopts, comment="")

Common statements

Generally, can not use r syntax in these chunks

Data can not be used in different chunks

proc means data=sashelp.class  ;
run;

proc freq data=sashelp.class  ;
table sex;
run;

proc contents data=sashelp.class varnum  ;
run;
                            The MEANS Procedure

 Variable    N           Mean        Std Dev        Minimum        Maximum
 -------------------------------------------------------------------------
 Age        19     13.3157895      1.4926722     11.0000000     16.0000000
 Height     19     62.3368421      5.1270752     51.3000000     72.0000000
 Weight     19    100.0263158     22.7739335     50.5000000    150.0000000
 -------------------------------------------------------------------------
 
                                                                           
 
                            The FREQ Procedure

                                         Cumulative    Cumulative
         Sex    Frequency     Percent     Frequency      Percent
         --------------------------------------------------------
         F             9       47.37             9        47.37  
         M            10       52.63            19       100.00  
 
                                                                           
 
                          The CONTENTS Procedure

  Data Set Name        SASHELP.CLASS             Observations          19
  Member Type          DATA                      Variables             5 
  Engine               V9                        Indexes               0 
  Created              09/06/2017 22:55:32       Observation Length    40
  Last Modified        09/06/2017 22:55:32       Deleted Observations  0 
  Protection                                     Compressed            NO
  Data Set Type                                  Sorted                NO
  Label                Student Data                                      
  Data Representation  WINDOWS_64                                        
  Encoding             us-ascii  ASCII (ANSI)                            

                     Engine/Host Dependent Information

Data Set Page Size          65536                                          
Number of Data Set Pages    1                                              
First Data Page             1                                              
Max Obs per Page            1632                                           
Obs in First Data Page      19                                             
Number of Data Set Repairs  0                                              
ExtendObsCounter            YES                                            
Filename                    C:\Program                                     
                            Files\SASHome\SASFoundation\9.                 
                            4\core\sashelp\class.sas7bdat                  
Release Created             9.0401M5                                       
Host Created                X64_SR12R2                                     
Owner Name                  BUILTIN\Administrators                         
File Size                   128KB                                          
File Size (bytes)           131072                                         

                        Variables in Creation Order
 
                       #    Variable    Type    Len

                       1    Name        Char      8
                       2    Sex         Char      1
                       3    Age         Num       8
                       4    Height      Num       8
                       5    Weight      Num       8
proc sort data=sashelp.class Out= name ;
by name;
Run;

proc print data= name (obs=10) ;
run;
             Obs    Name       Sex    Age    Height    Weight

               1    Alfred      M      14     69.0      112.5
               2    Alice       F      13     56.5       84.0
               3    Barbara     F      13     65.3       98.0
               4    Carol       F      14     62.8      102.5
               5    Henry       M      14     63.5      102.5
               6    James       M      12     57.3       83.0
               7    Jane        F      12     59.8       84.5
               8    Janet       F      15     62.5      112.5
               9    Jeffrey     M      13     62.5       84.0
              10    John        M      12     59.0       99.5
proc transpose data= sashelp.class out= Field;
by name;
Run;

proc print data= field (obs=10) ;
run;
                     Obs     Name      _NAME_     COL1

                       1    Alfred     Age        14.0
                       2    Alfred     Height     69.0
                       3    Alfred     Weight    112.5
                       4    Alice      Age        13.0
                       5    Alice      Height     56.5
                       6    Alice      Weight     84.0
                       7    Barbara    Age        13.0
                       8    Barbara    Height     65.3
                       9    Barbara    Weight     98.0
                      10    Carol      Age        14.0
 
DATA ab;
set sashelp.class;
IF sex="F" then message='A is greater';
Else message='B is greater';
Run; 

proc print data=ab (obs=10);
run;
     Obs    Name       Sex    Age    Height    Weight      message

       1    Alfred      M      14     69.0      112.5    B is greater
       2    Alice       F      13     56.5       84.0    A is greater
       3    Barbara     F      13     65.3       98.0    A is greater
       4    Carol       F      14     62.8      102.5    A is greater
       5    Henry       M      14     63.5      102.5    B is greater
       6    James       M      12     57.3       83.0    B is greater
       7    Jane        F      12     59.8       84.5    A is greater
       8    Janet       F      15     62.5      112.5    A is greater
       9    Jeffrey     M      13     62.5       84.0    B is greater
      10    John        M      12     59.0       99.5    B is greater
proc format;
   value AGEnew
        11 = '1: NEW' 
        12 = '2: NEW'
        13 = '3: NEW' 
        14 = '4: NEW'
        15 = '5: NEW'
        16 = '6: NEW'        
        ;
        run;
        
DATA ab;
set sashelp.class;
Format AGE AGEnew.;
Run;
        
proc freq data=ab;
        table AGE;
        run;
        
                            The FREQ Procedure

                                           Cumulative    Cumulative
           Age    Frequency     Percent     Frequency      Percent
        -----------------------------------------------------------
        1: NEW           2       10.53             2        10.53  
        2: NEW           5       26.32             7        36.84  
        3: NEW           3       15.79            10        52.63  
        4: NEW           4       21.05            14        73.68  
        5: NEW           4       21.05            18        94.74  
        6: NEW           1        5.26            19       100.00  
Data Mathdata;
A= 10.12345;
B=20;
C= mean (a,b);
D= Min(a,b);
E= Max(a,b); 
F = log(a);
G= round(a,0.02);
H= floor(a );

Run;

proc print data=Mathdata;
run;

Data mathdata;
Set  sashelp.Iris;
Sum = sum (of SepalLength, SepalWIDTH);
Diff = SepalLength- SepalWIDTH;
Mult = SepalLength* SepalWIDTH;
Div= SepalLength/ SepalWIDTH;
Run;

proc print data=mathdata (obs=10);
run;
Obs       A        B       C          D        E       F         G       H

 1     10.1235    20    15.0617    10.1235    20    2.31485    10.12    10
 
                                                                           
 
                  Sepal  Sepal   Petal  Petal
   Obs  Species  Length  Width  Length  Width  Sum  Diff  Mult    Div

     1  Setosa     50      33     14      2     83   17   1650  1.51515
     2  Setosa     46      34     14      3     80   12   1564  1.35294
     3  Setosa     46      36     10      2     82   10   1656  1.27778
     4  Setosa     51      33     17      5     84   18   1683  1.54545
     5  Setosa     55      35     13      2     90   20   1925  1.57143
     6  Setosa     48      31     16      2     79   17   1488  1.54839
     7  Setosa     52      34     14      2     86   18   1768  1.52941
     8  Setosa     49      36     14      1     85   13   1764  1.36111
     9  Setosa     44      32     13      2     76   12   1408  1.37500
    10  Setosa     50      35     16      6     85   15   1750  1.42857
 Data AB;
set sashelp.class; Rename AGE= AGENEW;
Run;

proc print data=AB;
run;
            Obs    Name       Sex    AGENEW    Height    Weight

              1    Alfred      M       14       69.0      112.5
              2    Alice       F       13       56.5       84.0
              3    Barbara     F       13       65.3       98.0
              4    Carol       F       14       62.8      102.5
              5    Henry       M       14       63.5      102.5
              6    James       M       12       57.3       83.0
              7    Jane        F       12       59.8       84.5
              8    Janet       F       15       62.5      112.5
              9    Jeffrey     M       13       62.5       84.0
             10    John        M       12       59.0       99.5
             11    Joyce       F       11       51.3       50.5
             12    Judy        F       14       64.3       90.0
             13    Louise      F       12       56.3       77.0
             14    Mary        F       15       66.5      112.0
             15    Philip      M       16       72.0      150.0
             16    Robert      M       12       64.8      128.0
             17    Ronald      M       15       67.0      133.0
             18    Thomas      M       11       57.5       85.0
             19    William     M       15       66.5      112.0
Data Mathdata;
Text = "Hello World";
Text1= substr(Text, 6, 2);
Run;

proc print data=mathdata  ;
run;
                        Obs       Text        Text1

                         1     Hello World      W  
Data ABC;
set sashelp.class;
agenew= input (age, best.); 
Run;

proc print data=abc  ;
run;
        Obs    Name       Sex    Age    Height    Weight    agenew

          1    Alfred      M      14     69.0      112.5      14  
          2    Alice       F      13     56.5       84.0      13  
          3    Barbara     F      13     65.3       98.0      13  
          4    Carol       F      14     62.8      102.5      14  
          5    Henry       M      14     63.5      102.5      14  
          6    James       M      12     57.3       83.0      12  
          7    Jane        F      12     59.8       84.5      12  
          8    Janet       F      15     62.5      112.5      15  
          9    Jeffrey     M      13     62.5       84.0      13  
         10    John        M      12     59.0       99.5      12  
         11    Joyce       F      11     51.3       50.5      11  
         12    Judy        F      14     64.3       90.0      14  
         13    Louise      F      12     56.3       77.0      12  
         14    Mary        F      15     66.5      112.0      15  
         15    Philip      M      16     72.0      150.0      16  
         16    Robert      M      12     64.8      128.0      12  
         17    Ronald      M      15     67.0      133.0      15  
         18    Thomas      M      11     57.5       85.0      11  
         19    William     M      15     66.5      112.0      15  
Data ABC;
set sashelp.class;
agenew= put (age, best.); 
Run;

proc contents data=abc  ;
run;
                          The CONTENTS Procedure

Data Set Name        WORK.ABC                      Observations          19
Member Type          DATA                          Variables             6 
Engine               V9                            Indexes               0 
Created              07/06/2022 11:57:24           Observation Length    48
Last Modified        07/06/2022 11:57:24           Deleted Observations  0 
Protection                                         Compressed            NO
Data Set Type                                      Sorted                NO
Label                                                                      
Data Representation  WINDOWS_64                                            
Encoding             wlatin1  Western (Windows)                            

                     Engine/Host Dependent Information

Data Set Page Size          65536                                          
Number of Data Set Pages    1                                              
First Data Page             1                                              
Max Obs per Page            1361                                           
Obs in First Data Page      19                                             
Number of Data Set Repairs  0                                              
ExtendObsCounter            YES                                            
Filename                    C:\Users\hed2\AppData\Local\Temp\1\SAS         
                            Temporary                                      
                            Files\_TD17236_HDW02234493_\abc.sas7bdat       
Release Created             9.0401M5                                       
Host Created                X64_10PRO                                      
Owner Name                  NIH\hed2                                       
File Size                   128KB                                          
File Size (bytes)           131072                                         

                Alphabetic List of Variables and Attributes
 
                       #    Variable    Type    Len

                       3    Age         Num       8
                       4    Height      Num       8
                       1    Name        Char      8
                       2    Sex         Char      1
                       5    Weight      Num       8
                       6    agenew      Char     12
Data ABC;
set sashelp.class;
Length agenew $10.;
Label agenew=“New age”;
Run;

proc contents data=abc  ;
run;
 
                          The CONTENTS Procedure

Data Set Name        WORK.ABC                      Observations          19
Member Type          DATA                          Variables             6 
Engine               V9                            Indexes               0 
Created              07/06/2022 11:57:24           Observation Length    48
Last Modified        07/06/2022 11:57:24           Deleted Observations  0 
Protection                                         Compressed            NO
Data Set Type                                      Sorted                NO
Label                                                                      
Data Representation  WINDOWS_64                                            
Encoding             wlatin1  Western (Windows)                            

                     Engine/Host Dependent Information

Data Set Page Size          65536                                          
Number of Data Set Pages    1                                              
First Data Page             1                                              
Max Obs per Page            1361                                           
Obs in First Data Page      19                                             
Number of Data Set Repairs  0                                              
ExtendObsCounter            YES                                            
Filename                    C:\Users\hed2\AppData\Local\Temp\1\SAS         
                            Temporary                                      
                            Files\_TD16664_HDW02234493_\abc.sas7bdat       
Release Created             9.0401M5                                       
Host Created                X64_10PRO                                      
Owner Name                  NIH\hed2                                       
File Size                   128KB                                          
File Size (bytes)           131072                                         

                Alphabetic List of Variables and Attributes
 
               #    Variable    Type    Len    Label

               3    Age         Num       8                 
               4    Height      Num       8                 
               1    Name        Char      8                 
               2    Sex         Char      1                 
               5    Weight      Num       8                 
               6    agenew      Char     10    “New age”
proc report data=sashelp.class;
Column age;
Define age / display;
Run;
                                       Age
                                        14
                                        13
                                        13
                                        14
                                        14
                                        12
                                        12
                                        15
                                        13
                                        12
                                        11
                                        14
                                        12
                                        15
                                        16
                                        12
                                        15
                                        11
                                        15
data ab;
set sashelp.class;
num=rand("normal");
run;

proc print data=ab (obs=10); 
run;
       Obs    Name       Sex    Age    Height    Weight       num

         1    Alfred      M      14     69.0      112.5     0.53129
         2    Alice       F      13     56.5       84.0     1.46501
         3    Barbara     F      13     65.3       98.0     1.79722
         4    Carol       F      14     62.8      102.5    -0.68748
         5    Henry       M      14     63.5      102.5     0.52371
         6    James       M      12     57.3       83.0     1.01352
         7    Jane        F      12     59.8       84.5     0.56256
         8    Janet       F      15     62.5      112.5     0.47257
         9    Jeffrey     M      13     62.5       84.0     0.88518
        10    John        M      12     59.0       99.5     0.67657
Data Mathdata;
Text = "Hello";
Text1= "World";
Text2= text || " " ||text1;
Run;

proc print data=Mathdata  ; 
run;
                   Obs    Text     Text1       Text2

                    1     Hello    World    Hello World
Data Mathdata;
Text = "Hello  World  ";
Text1= trim(text);
Text2= compress(text);
Run;

proc print data=Mathdata  ; 
run;
             Obs        Text           Text1          Text2

              1     Hello  World    Hello  World    HelloWorld
Data Mathdata;
Text = "Hello World";
indextext=  index(text, "or");
Run;

proc print data=Mathdata  ; 
run;
                      Obs       Text        indextext

                       1     Hello World        8    
Data Mathdata;
Text = "Hello World";
upcase=  upcase(text );
lowcase=  lowcase(text );
propcase=  propcase(text );
Run;

proc print data=Mathdata  ; 
run;
      Obs       Text          upcase         lowcase       propcase

       1     Hello World    HELLO WORLD    hello world    Hello World
/* Dedup, original data has 19 observations  */
proc sort data = sashelp.class out =  dedup
nodupkeys;
by height; 
run;

proc print data= dedup;
run;
             Obs    Name       Sex    Age    Height    Weight

               1    Joyce       F      11     51.3       50.5
               2    Louise      F      12     56.3       77.0
               3    Alice       F      13     56.5       84.0
               4    James       M      12     57.3       83.0
               5    Thomas      M      11     57.5       85.0
               6    John        M      12     59.0       99.5
               7    Jane        F      12     59.8       84.5
               8    Janet       F      15     62.5      112.5
               9    Carol       F      14     62.8      102.5
              10    Henry       M      14     63.5      102.5
              11    Judy        F      14     64.3       90.0
              12    Robert      M      12     64.8      128.0
              13    Barbara     F      13     65.3       98.0
              14    Mary        F      15     66.5      112.0
              15    Ronald      M      15     67.0      133.0
              16    Alfred      M      14     69.0      112.5
              17    Philip      M      16     72.0      150.0
data where;
set sashelp.class;
where sex ne "F";
/*if */
run;

proc print data= where;
run;
             Obs    Name       Sex    Age    Height    Weight

               1    Alfred      M      14     69.0      112.5
               2    Henry       M      14     63.5      102.5
               3    James       M      12     57.3       83.0
               4    Jeffrey     M      13     62.5       84.0
               5    John        M      12     59.0       99.5
               6    Philip      M      16     72.0      150.0
               7    Robert      M      12     64.8      128.0
               8    Ronald      M      15     67.0      133.0
               9    Thomas      M      11     57.5       85.0
              10    William     M      15     66.5      112.0
2          /*create a macro to calcualte descriptive stats */
3          %macro means(var_avg) ;
4          
5          /*calculate means*/
6          proc means data=sashelp.class StackODSOutput n mean std  min p5
6        ! p95 max nmiss;
7          var  &var_avg;
8          class sex;
9          ods output summary=result2;
10         run;
11         
12         /*append then output*/
13         data masterresult2;                  * combine results;
14         set masterresult2 result2;
15         run;
16         
17         %mend means;
18         
19         /*use macro to merge all descriptive stats */
20         data masterresult2 ;
21         set _null_;
22         run;

NOTE: The data set WORK.MASTERRESULT2 has 0 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

23         
24         %let vars=
25         age
26         height
27         weight
28         ;
29         
30         %macro model ;
31         %do i=1 %to %sysfunc(countw(&vars));
32         
33         %let x=%scan(&vars,&i);
34          %means( &x )
35         
36         %end;
37         %mend model;
38         
39         %model;
NOTE: The data set WORK.RESULT2 has 2 observations and 12 variables.
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The PROCEDURE MEANS printed page 1.
NOTE: PROCEDURE MEANS used (Total process time):
      real time           0.03 seconds
      cpu time            0.04 seconds
      

NOTE: There were 0 observations read from the data set WORK.MASTERRESULT2.
NOTE: There were 2 observations read from the data set WORK.RESULT2.
NOTE: The data set WORK.MASTERRESULT2 has 2 observations and 12 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

NOTE: The data set WORK.RESULT2 has 2 observations and 12 variables.
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The PROCEDURE MEANS printed page 2.
NOTE: PROCEDURE MEANS used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds
      

WARNING: Multiple lengths were specified for the variable Variable by 
         input data set(s). This can cause truncation of data.
NOTE: There were 2 observations read from the data set WORK.MASTERRESULT2.
NOTE: There were 2 observations read from the data set WORK.RESULT2.
NOTE: The data set WORK.MASTERRESULT2 has 4 observations and 12 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds
      

NOTE: The data set WORK.RESULT2 has 2 observations and 12 variables.
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The PROCEDURE MEANS printed page 3.
NOTE: PROCEDURE MEANS used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

WARNING: Multiple lengths were specified for the variable Variable by 
         input data set(s). This can cause truncation of data.
NOTE: There were 4 observations read from the data set WORK.MASTERRESULT2.
NOTE: There were 2 observations read from the data set WORK.RESULT2.
NOTE: The data set WORK.MASTERRESULT2 has 6 observations and 12 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

40         
41         proc print data= masterresult2;
42         run;

NOTE: There were 6 observations read from the data set WORK.MASTERRESULT2.
NOTE: The PROCEDURE PRINT printed page 4.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

43         
                            The MEANS Procedure

                         Analysis Variable : Age 
 
        N
Sex   Obs    N           Mean        Std Dev        Minimum       5th Pctl
--------------------------------------------------------------------------
F       9    9      13.222222       1.394433      11.000000      11.000000

M      10   10      13.400000       1.646545      11.000000      11.000000
--------------------------------------------------------------------------

                         Analysis Variable : Age 
 
                     N                                      N
             Sex   Obs      95th Pctl         Maximum    Miss
             ------------------------------------------------
             F       9      15.000000       15.000000       0

             M      10      16.000000       16.000000       0
             ------------------------------------------------
 
                                                                           
 
                            The MEANS Procedure

                       Analysis Variable : Height 
 
        N
Sex   Obs    N           Mean        Std Dev        Minimum       5th Pctl
--------------------------------------------------------------------------
F       9    9      60.588889       5.018328      51.300000      51.300000

M      10   10      63.910000       4.937937      57.300000      57.300000
--------------------------------------------------------------------------

                       Analysis Variable : Height 
 
                     N                                      N
             Sex   Obs      95th Pctl         Maximum    Miss
             ------------------------------------------------
             F       9      66.500000       66.500000       0

             M      10      72.000000       72.000000       0
             ------------------------------------------------
 
                                                                           
 
                            The MEANS Procedure

                       Analysis Variable : Weight 
 
        N
Sex   Obs    N           Mean        Std Dev        Minimum       5th Pctl
--------------------------------------------------------------------------
F       9    9      90.111111      19.383914      50.500000      50.500000

M      10   10     108.950000      22.727186      83.000000      83.000000
--------------------------------------------------------------------------

                       Analysis Variable : Weight 
 
                     N                                      N
             Sex   Obs      95th Pctl         Maximum    Miss
             ------------------------------------------------
             F       9     112.500000      112.500000       0

             M      10     150.000000      150.000000       0
             ------------------------------------------------
 
                                                                           
 
Obs   Sex   NObs   _control_   Variable    N           Mean         StdDev

 1     F      9                  Age       9      13.222222       1.394433
 2     M     10        1         Age      10      13.400000       1.646545
 3     F      9                  Hei       9      60.588889       5.018328
 4     M     10        1         Hei      10      63.910000       4.937937
 5     F      9                  Wei       9      90.111111      19.383914
 6     M     10        1         Wei      10     108.950000      22.727186

Obs            Min             P5            P95            Max   NMiss

 1       11.000000      11.000000      15.000000      15.000000     0  
 2       11.000000      11.000000      16.000000      16.000000     0  
 3       51.300000      51.300000      66.500000      66.500000     0  
 4       57.300000      57.300000      72.000000      72.000000     0  
 5       50.500000      50.500000     112.500000     112.500000     0  
 6       83.000000      83.000000     150.000000     150.000000     0  
ods   listing close;
ods trace on;
ods output ParameterEstimates= ParameterEstimates  ;
proc glm data=sashelp.class;
model height=age;
run;
ods trace off;
ods listing;

proc print data=ParameterEstimates;
run;
  Obs  Dependent  Parameter      Estimate        StdErr   tValue   Probt

   1    Height    Intercept   25.22388451    6.52168912     3.87  0.0012
   2    Height    Age          2.78713911    0.48688163     5.72  <.0001

right, left join

2          data class2;
3          input name $   score;
4          datalines;

NOTE: The data set WORK.CLASS2 has 3 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

8          ;
9          run;
10         
11         proc sql;
12         create table class_c as
13           select *
14             from sashelp.class as a
15            left join class2 as b
16              on a.name = b.name;
WARNING: Variable name already exists on file WORK.CLASS_C.
NOTE: Table WORK.CLASS_C created, with 19 rows and 6 columns.

17         quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
      

18         
19         proc print data=class_c;
20         run;

NOTE: There were 19 observations read from the data set WORK.CLASS_C.
NOTE: The PROCEDURE PRINT printed page 1.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
      

21          
22         proc sql;
23         create table class_d as
24           select *
25             from class2 as a
26            right join sashelp.class as b
27              on a.name = b.name;
WARNING: Variable Name already exists on file WORK.CLASS_D.
NOTE: Table WORK.CLASS_D created, with 19 rows and 6 columns.

28         quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds
      

29         
30         proc print data=class_d;
31         run;

NOTE: There were 19 observations read from the data set WORK.CLASS_D.
NOTE: The PROCEDURE PRINT printed page 2.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

32         
         Obs    Name       Sex    Age    Height    Weight    score

           1    Alfred      M      14     69.0      112.5      85 
           2    Alice       F      13     56.5       84.0      89 
           3    Barbara     F      13     65.3       98.0       . 
           4    Carol       F      14     62.8      102.5       . 
           5    Henry       M      14     63.5      102.5       . 
           6    James       M      12     57.3       83.0       . 
           7    Jane        F      12     59.8       84.5       . 
           8    Janet       F      15     62.5      112.5       . 
           9    Jeffrey     M      13     62.5       84.0       . 
          10    John        M      12     59.0       99.5       . 
          11    Joyce       F      11     51.3       50.5       . 
          12    Judy        F      14     64.3       90.0       . 
          13    Louise      F      12     56.3       77.0       . 
          14    Mary        F      15     66.5      112.0       . 
          15    Philip      M      16     72.0      150.0       . 
          16    Robert      M      12     64.8      128.0       . 
          17    Ronald      M      15     67.0      133.0       . 
          18    Thomas      M      11     57.5       85.0       . 
          19    William     M      15     66.5      112.0       . 
 
                                                                           
 
         Obs     name     score    Sex    Age    Height    Weight

           1    Alfred      85      M      14     69.0      112.5
           2    Alice       89      F      13     56.5       84.0
           3                 .      F      13     65.3       98.0
           4                 .      F      14     62.8      102.5
           5                 .      M      14     63.5      102.5
           6                 .      M      12     57.3       83.0
           7                 .      F      12     59.8       84.5
           8                 .      F      15     62.5      112.5
           9                 .      M      13     62.5       84.0
          10                 .      M      12     59.0       99.5
          11                 .      F      11     51.3       50.5
          12                 .      F      14     64.3       90.0
          13                 .      F      12     56.3       77.0
          14                 .      F      15     66.5      112.0
          15                 .      M      16     72.0      150.0
          16                 .      M      12     64.8      128.0
          17                 .      M      15     67.0      133.0
          18                 .      M      11     57.5       85.0
          19                 .      M      15     66.5      112.0

full join

2          data class2;
3          input name $   score;
4          datalines;

NOTE: The data set WORK.CLASS2 has 3 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

8          ;
9          run;
10         
11         proc sql;
12         create table class_e as
13           select *
14             from sashelp.class as a
15            full   join class2 as b
16              on a.name = b.name;
WARNING: Variable name already exists on file WORK.CLASS_E.
NOTE: Table WORK.CLASS_E created, with 20 rows and 6 columns.

17         quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds
      

18         
19         proc print data=class_e;
20         run;

NOTE: There were 20 observations read from the data set WORK.CLASS_E.
NOTE: The PROCEDURE PRINT printed page 1.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
      

21         
         Obs    Name       Sex    Age    Height    Weight    score

           1    Alfred      M      14     69.0      112.5      85 
           2    Alice       F      13     56.5       84.0      89 
           3    Barbara     F      13     65.3       98.0       . 
           4    Carol       F      14     62.8      102.5       . 
           5                        .       .          .       99 
           6    Henry       M      14     63.5      102.5       . 
           7    James       M      12     57.3       83.0       . 
           8    Jane        F      12     59.8       84.5       . 
           9    Janet       F      15     62.5      112.5       . 
          10    Jeffrey     M      13     62.5       84.0       . 
          11    John        M      12     59.0       99.5       . 
          12    Joyce       F      11     51.3       50.5       . 
          13    Judy        F      14     64.3       90.0       . 
          14    Louise      F      12     56.3       77.0       . 
          15    Mary        F      15     66.5      112.0       . 
          16    Philip      M      16     72.0      150.0       . 
          17    Robert      M      12     64.8      128.0       . 
          18    Ronald      M      15     67.0      133.0       . 
          19    Thomas      M      11     57.5       85.0       . 
          20    William     M      15     66.5      112.0       . 

or using merge for appending

data class2;
input name $   score;
datalines;
Alfred  85
Alice 89
Daniel 99
;
run;
 
data class_f;
merge  sashelp.class class2;
by name;
run;

proc print data=class_f;
run;
         Obs    Name       Sex    Age    Height    Weight    score

           1    Alfred      M      14     69.0      112.5      85 
           2    Alice       F      13     56.5       84.0      89 
           3    Barbara     F      13     65.3       98.0       . 
           4    Carol       F      14     62.8      102.5       . 
           5    Daniel              .       .          .       99 
           6    Henry       M      14     63.5      102.5       . 
           7    James       M      12     57.3       83.0       . 
           8    Jane        F      12     59.8       84.5       . 
           9    Janet       F      15     62.5      112.5       . 
          10    Jeffrey     M      13     62.5       84.0       . 
          11    John        M      12     59.0       99.5       . 
          12    Joyce       F      11     51.3       50.5       . 
          13    Judy        F      14     64.3       90.0       . 
          14    Louise      F      12     56.3       77.0       . 
          15    Mary        F      15     66.5      112.0       . 
          16    Philip      M      16     72.0      150.0       . 
          17    Robert      M      12     64.8      128.0       . 
          18    Ronald      M      15     67.0      133.0       . 
          19    Thomas      M      11     57.5       85.0       . 
          20    William     M      15     66.5      112.0       . 

inner join

2          data class2;
3          input name $   score;
4          datalines;

NOTE: The data set WORK.CLASS2 has 3 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

8          ;
9          run;
10         
11         proc sql;
12         create table class_e as
13           select *
14             from sashelp.class as a
15            inner join class2 as b
16              on a.name = b.name;
WARNING: Variable name already exists on file WORK.CLASS_E.
NOTE: Table WORK.CLASS_E created, with 2 rows and 6 columns.

17         quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
      

18         
19         proc print data=class_e;
20         run;

NOTE: There were 2 observations read from the data set WORK.CLASS_E.
NOTE: The PROCEDURE PRINT printed page 1.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
      

21         
         Obs     Name     Sex    Age    Height    Weight    score

          1     Alfred     M      14     69.0      112.5      85 
          2     Alice      F      13     56.5       84.0      89 

minus join

2          data class2;
3          input name $   score;
4          datalines;

NOTE: The data set WORK.CLASS2 has 3 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

8          ;
9          run;
10         
11         proc sql;
12         create table class_e as
13           select *
14             from sashelp.class as a
15            left join class2 as b
16              on a.name = b.name
17              where b.name is NULL;
WARNING: Variable name already exists on file WORK.CLASS_E.
NOTE: Table WORK.CLASS_E created, with 17 rows and 6 columns.

18         quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds
      

19         
20         proc print data=class_e;
21         run;

NOTE: There were 17 observations read from the data set WORK.CLASS_E.
NOTE: The PROCEDURE PRINT printed page 1.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
      

22         
         Obs    Name       Sex    Age    Height    Weight    score

           1    Barbara     F      13     65.3       98.0      .  
           2    Carol       F      14     62.8      102.5      .  
           3    Henry       M      14     63.5      102.5      .  
           4    James       M      12     57.3       83.0      .  
           5    Jane        F      12     59.8       84.5      .  
           6    Janet       F      15     62.5      112.5      .  
           7    Jeffrey     M      13     62.5       84.0      .  
           8    John        M      12     59.0       99.5      .  
           9    Joyce       F      11     51.3       50.5      .  
          10    Judy        F      14     64.3       90.0      .  
          11    Louise      F      12     56.3       77.0      .  
          12    Mary        F      15     66.5      112.0      .  
          13    Philip      M      16     72.0      150.0      .  
          14    Robert      M      12     64.8      128.0      .  
          15    Ronald      M      15     67.0      133.0      .  
          16    Thomas      M      11     57.5       85.0      .  
          17    William     M      15     66.5      112.0      .  
  *** Load utility macros;
%include "C:\Users\hed2\Downloads\mybook2\mybook2\sasmacro\create_table1.sas";

  *** Specify input and output data sets, and the column variable.;
%let INPUT_DATA  = sashelp.class;
%let OUTPUT_DATA = Table1 ;
%let COLVAR      = sex;

  /*chort*/
 *** %AddText(text=Height);
 *** %CategoricalRowVar2(rowVar=);
%ContinuousRowVar2(rowVar=height );
 *** %AddText(text=);

%ContinuousRowVar2(rowVar=weight );
%ContinuousRowVar2(rowVar=Age );

proc print data= table1;
run;

/* Export Table 1 as a CSV file*/ 
proc export data=Table1 replace label
    outfile="C:\Users\hed2\Downloads\mybook2\mybook2\sasmacro\table1.csv"
    dbms=csv;
run;  
 
           Obs           Variable            freqpct_meansd

            1     Height : Mean (SD) [N]     62.3 (5.1) [19] 
            2     Weight : Mean (SD) [N]    100.0 (22.8) [19]
            3     Age : Mean (SD) [N]        13.3 (1.5) [19] 

                  freqpct_meansd_
           Obs          g1           freqpct_meansd_g2      Prob

            1     60.6 (5.0) [9]      63.9 (4.9) [10]     0.1943
            2     90.1 (19.4) [9]    109.0 (22.7) [10]    0.1476
            3     13.2 (1.4) [9]      13.4 (1.6) [10]     0.8695
 *** Load utility macros;
%include "C:\Users\hed2\Downloads\mybook2\mybook2\sasmacro/Utility Macros_updated_NG.sas";

/* 
  By  counts 
%let yourdata = sashelp.class;
%let output_data= By_sex;
%let formatsfolder= ; 
%let yourfolder = ;
%let varlist_cat =  ;
%let varlist_cont = age heigt weight; 
%let output_order = height weight age;
%let decimal_max =3;
%let group_by = sex;
%let group_by_missing=0;

%Table_summary;
*/
proc glm data= sashelp.class;
model height=age;
Run;
                             The GLM Procedure

                  Number of Observations Read          19
                  Number of Observations Used          19
 
                                                                           
 
                             The GLM Procedure
 
                       Dependent Variable: Height   

                                     Sum of
 Source                    DF       Squares   Mean Square  F Value  Pr > F

 Model                      1   311.5434756   311.5434756    32.77  <.0001

 Error                     17   161.6207349     9.5071021                 

 Corrected Total           18   473.1642105                               

            R-Square     Coeff Var      Root MSE    Height Mean

            0.658426      4.946287      3.083359       62.33684


 Source                    DF     Type I SS   Mean Square  F Value  Pr > F

 Age                        1   311.5434756   311.5434756    32.77  <.0001


 Source                    DF   Type III SS   Mean Square  F Value  Pr > F

 Age                        1   311.5434756   311.5434756    32.77  <.0001

                                       Standard
     Parameter         Estimate           Error    t Value    Pr > |t|

     Intercept      25.22388451      6.52168912       3.87      0.0012
     Age             2.78713911      0.48688163       5.72      <.0001