Help using Base SAS procedures

Proc REPORT and numeric arrays

Reply
Respected Advisor
Posts: 3,799

Proc REPORT and numeric arrays

Anyone have an idea why line 913 below produces an array with 6 elements, each dotted variable is doubled.  While using variable name constants in line 920 produces the expect 3 elements.  Maybe I should check the UG. :smileyblush:

909 proc report data=sashelp.class nowd list;

910 columns _numeric_;

911

912 compute before;

913 array _nb

  • age.sum height.sum weight.sum;
  • 914 rcn = seenum(dim(_nb),'DIM=');

    915 do i = 1 to dim(_nb);

    916 rcn = seenum(_nb,cats(catx('_',vname(_nb),i),'='));

    917 end;

    918 endcomp;

    919 compute after;

    920 array _na

  • 'age.sum'n 'height.sum'n 'weight.sum'n;
  • 921 rcn = seenum(dim(_na),'DIM=');

    922 do i = 1 to dim(_na);

    923 rcn = seenum(_na,cats(catx('_',vname(_na),i),'='));

    924 end;

    925 endcomp;

    926

    927 run;

    PROC REPORT DATA=SASHELP.CLASS LS=123 PS=63 SPLIT="/" CENTER ;

    COLUMN ( Age Height Weight );

    DEFINE Age / SUM FORMAT= BEST9. WIDTH=9 SPACING=2 RIGHT "Age" ;

    DEFINE Height / SUM FORMAT= BEST9. WIDTH=9 SPACING=2 RIGHT "Height" ;

    DEFINE Weight / SUM FORMAT= BEST9. WIDTH=9 SPACING=2 RIGHT "Weight" ;

    RBREAK BEFORE / ;

    RBREAK AFTER / ;

    COMPUTE BEFORE ;

    array _nb [ * ] age.sum height.sum weight.sum;

    rcn = seenum(dim(_nb), 'DIM=');

    do i = 1 to dim(_nb);

    rcn = seenum(_nb [ i ], cats(catx('_', vname(_nb [ i ]), i), '='));

    end;

    ENDCOMP;

    COMPUTE AFTER ;

    array _na [ * ] 'age.sum'n 'height.sum'n 'weight.sum'n;

    rcn = seenum(dim(_na), 'DIM=');

    do i = 1 to dim(_na);

    rcn = seenum(_na [ i ], cats(catx('_', vname(_na [ i ]), i), '='));

    end;

    ENDCOMP;

    RUN;

    DIM= 6

    Age.SUM_1= 253

    Age.SUM_2= 253

    Height.SUM_3= 1184.4

    Height.SUM_4= 1184.4

    Weight.SUM_5= 1900.5

    Weight.SUM_6= 1900.5

    DIM= 3

    Age.SUM_1= 253

    Height.SUM_2= 1184.4

    Weight.SUM_3= 1900.5

    NOTE: There were 19 observations read from the data set SASHELP.CLASS.

    NOTE: PROCEDURE REPORT used (Total process time):

    real time 0.04 seconds

    cpu time 0.04 seconds

    PROC Star
    Posts: 7,474

    Proc REPORT and numeric arrays

    Posted in reply to data_null__

    DN,

    Is the difference any more than that the one call included the nowd option while the other didn't?

    Respected Advisor
    Posts: 3,799

    Re: Proc REPORT and numeric arrays

    There is only one PROC REPORT numbered lines 909-927 The unnumbered lines are result of LIST option and output from SEENUM.

    PROC Star
    Posts: 7,474

    Re: Proc REPORT and numeric arrays

    Posted in reply to data_null__

    I can't find anything in the documentation that says that compound names have to be referred to with name literals.  I would think this one should be sent to tech support and will result in a hotfix.

    Super User
    Posts: 10,035

    Re: Proc REPORT and numeric arrays

    Posted in reply to data_null__

    Null.

    Because age.sum maps two variable (age and 'age.sum'n) which age is for computed usage,'age.sum'n is for

    computed before/after usage. So you will get six variables ,while another statement is three varibales.

    So if you want get three variables before computed block, then use another three temp variables to hold these value of three variables.

    PROC REPORT DATA=SASHELP.CLASS LS=123 PS=63 SPLIT="/" CENTER   ;

    COLUMN ( Age Height Weight );

    DEFINE Age / SUM FORMAT= BEST9. WIDTH=9 SPACING=2 RIGHT "Age" ;

    DEFINE Height / SUM FORMAT= BEST9. WIDTH=9 SPACING=2 RIGHT "Height" ;

    DEFINE Weight / SUM FORMAT= BEST9. WIDTH=9 SPACING=2 RIGHT "Weight" ;

    RBREAK BEFORE / ;

    RBREAK AFTER / ;

    COMPUTE BEFORE ;

    _age=age.sum; _height=height.sum; _weight=weight.sum;

    array _nb [ * ] _age _height _weight;

    rcn = seenum(dim(_nb), 'DIM=');

    do i = 1 to dim(_nb);

    rcn = seenum(_nb [ i ], cats(catx('_', vname(_nb [ i ]), i), '='));

    end;

    ENDCOMP;

    COMPUTE AFTER ;

    array _na [ * ] 'age.sum'n 'height.sum'n 'weight.sum'n;

    rcn = seenum(dim(_na), 'DIM=');

    do i = 1 to dim(_na);

    rcn = seenum(_na [ i ], cats(catx('_', vname(_na [ i ]), i), '='));

    end;

    ENDCOMP;

    RUN;

    Ksharp

    Ask a Question
    Discussion stats
    • 4 replies
    • 543 views
    • 0 likes
    • 3 in conversation