SmryEachVar ApDev Introduction

From sasCommunity
Jump to: navigation, search

Download the SmryEachVar-ApDev-Introduction zip of 2015-May-07

Modules

The programs shown are from suite.2, the final set of working programs.

Allocate Data Set Name

02-data-sashelp-class

%let  in_data = sashelp.class;
%let out_data = work.summary_each_var_class;
 
%include 'proc-2-freq-smry.sas';

02-data-sashelp-heart

%let  in_data = sashelp.heart;
%let out_data = work.summary_each_var_heart;
 
%include 'proc-2-freq-smry.sas';

Main: Calling Routines and Subroutines

proc-2-freq-smry

******** echo included statements to log?;
*options source2;
 
**** split two-level in-data :: libref.data;
%let libname = %scan(&in_data, 1,.);
%let memname = %scan(&in_data,-1,.);
%put note: &=in_data &=libname &=memname;
 
******** create input list: control data set;
%include 'make-list-vars-sql.sas';
 
******** call item processing routines;
%let     proc_name  = 'proc-freq.sas';
%let     proc_where = 1; * all? or only char?;
%let     proc_where = type eq 'char';
%include 'proc-list-vars-subset.sas';
 
%let     proc_name  = 'proc-summary.sas';
%let     proc_where = type eq 'num';
%include 'proc-list-vars-subset.sas';
 
%include 'proc-print-out-data.sas';

List Processing

Making a List of Variable Names: make-list-vars-sql.sas

PROC sql; create table list_variables as
          select libname, memname, name, type
          from   dictionary.columns
          where  libname eq "%upcase(&libname)"
            and  memname eq "%upcase(&memname)";
          quit;

Processing a List of Names: proc-list-vars-subset.sas

%put note: &=proc_name &=proc_where;
 
PROC sql noprint;
         select catt('%let name=', name, ';'
                    ,'%let type=', type, ';'
                    ,"%include &proc_name ;")
         into  :_process_list  separated by ' '
         from   list_variables
         where &proc_where;       *  <---<<<  ;
         quit;
&_process_list


Processing

data-structure.sas

DATA standardized_data_structure
    (label = "freq/smry of &libname &memname");
     attrib name      length = $32
            valu_char length = $32 %* fragile! ;
            valu_num  length =   8
            count     length =   8
            percent   length =   8;
     retain name "&name";
set &syslast;
 
PROC append data = &syslast
            base = &out_data;
run;

Frequency Procedure: proc-freq.sas

%put note: &=libname &=memname &=name &=type;
 
PROC freq data   = &libname .&memname;
          tables   &name
                 /  noprint
          out    =  out_freq
         (rename =(&name = valu_&type));
 
%include 'data-structure.sas';

Summary Procedure: proc-summary.sas

%put note: &=libname &=memname &=name &=type;
 
PROC summary data   =  &libname..&memname;
             var       &name;
             output
                out =   out_summary
            (  drop =  _type_  _freq_
             rename = (_stat_ = valu_char
                       &name  = valu_num));
 
%include 'data-structure.sas';

Print Procedure: proc-print-out-data.sas

PROC print data = &out_data;
           title3 &out_data;
           title4 &in_data ;
           by     name notsorted;
           id     name;
run;

Example Output

sashelp.class

Applications Development -- Introduction
02-data-sashelp-class
work.summary_each_var_class
sashelp.class

          valu_
name      char       valu_num    count    percent

Name      Alfred         .          1      5.2632
          Alice          .          1      5.2632
          Barbara        .          1      5.2632
...
          Ronald         .          1      5.2632
          Thomas         .          1      5.2632
          William        .          1      5.2632

Sex       F              .          9     47.3684
          M              .         10     52.6316

Age       N            19.000       .       .
          MIN          11.000       .       .
          MAX          16.000       .       .
          MEAN         13.316       .       .
          STD           1.493       .       .

Height    N            19.000       .       .
          MIN          51.300       .       .
          MAX          72.000       .       .
          MEAN         62.337       .       .
          STD           5.127       .       .

Weight    N            19.000       .       .
          MIN          50.500       .       .
          MAX         150.000       .       .
          MEAN        100.026       .       .
          STD          22.774       .       .

sashelp.heart

Applications Development -- Introduction
02-data-sashelp-heart
work.summary_each_var_heart
sashelp.heart

name              valu_char                    valu_num    count    percent

Status            Alive                             .       3218    61.7777
                  Dead                              .       1991    38.2223

DeathCause                                          .       3218      .
                  Cancer                            .        539    27.0718
                  Cerebral Vascular Disease         .        378    18.9854
                  Coronary Heart Disease            .        605    30.3867
                  Other                             .        357    17.9307
                  Unknown                           .        112     5.6253

Sex               Female                            .       2873    55.1545
                  Male                              .       2336    44.8455

...

AgeCHDdiag        N                             1449.00        .      .
                  MIN                             32.00        .      .
                  MAX                             90.00        .      .
                  MEAN                            63.30        .      .
                  STD                             10.02        .      .

AgeAtStart        N                             5209.00        .      .
                  MIN                             28.00        .      .
                  MAX                             62.00        .      .
                  MEAN                            44.07        .      .
                  STD                              8.57        .      .
...

References

Ronald_J._Fehd macro.maven == the radical programmer (talk) 20:01, 6 May 2015 (CDT)