BookmarkSubscribeRSS Feed
oujiang
Calcite | Level 5

hi all:

    my code is:

proc report data=sashelp.class nowd split='*';

  column ('sex' sex) ('age' age) name ,( height  weight ) height=ht weight=wt  var2;

  define name / across '' ;

  define sex /  group '';

  define age / analysis '';

  define height / analysis  '';

  define weight / analysis  ''  ;

    define ht / analysis  '' noprint;

  define wt / analysis  ''  noprint;

  define var2 / computed " "

         style(column)={just=c protectspecialchars=off cellwidth=1.5in};

  compute var2 / character length=75;

     var2 = catt(put(wt,5.0),'(',put(ht,5.1),')');

  endcomp;

break after sex /summarize;

  rbreak after/ summarize dol dul;

run;

How to use the "proc report" to get the following data:

sexageAlfredAliceBarbaraCarolHenryJamesJaneJanetJeffreyJohnJoyceJudyLouiseMaryPhilipRobertRonaldThomasWilliam 
F119.56.58465.39862.8102.5..59.862.562.5112.5..51.350.564.39056.37766.5112.....811(545.3)
F119.56.58465.39862.8102.5..59.862.562.5112.5..51.350.564.39056.37766.5112.....811(545.3)
M13469112.5...63.5102.557.383..62.5845999.5....7215064.81286713357.58566.51121090(639.1)
M13469112.5...63.5102.557.383..62.5845999.5....7215064.81286713357.58566.51121090(639.1)
 25369112.556.58465.39862.8102.563.5102.557.38359.862.562.5112.562.5845999.551.350.564.39056.37766.51127215064.81286713357.58566.51121901( 1184)
1 REPLY 1
Cynthia_sas
SAS Super FREQ

Hi:

  I'm confused by a few things.

   

  First, you show a mixture of LISTING only options (DOL, DUL) with standard ODS style= overrides (for VAR2), so I wonder whether you want LISTING output AND ODS output or whether you want only ODS result files, such as RTF or PDF.

 

  Then, I am confused by the BREAK statement -- it seems to me that it is inserting an unnecessary summary line for every unique value of SEX, and in this context, at least, doesn't seem to serve any purpose. I'm also confused by your usage of AGE -- I would have expected you to get the N statistic or the MEAN statistic for AGE. Right now, you will get the SUM statistic (the total of all the AGE values -- since the default statistic for an ANALYSIS item is the SUM statistic -- and that doesn't make sense to me.)

  Third, it looks like you are trying to generate a report that I would call a "demographic" report. In which case, using SASHELP.CLASS, isn't really representative of what your data probably looks like. I would expect that you have patient or treatment data and you want to generate the type of report
shown on page 9, or 17 of this paper: http://www2.sas.com/proceedings/forum2008/173-2008.pdf or
shown (for LISTING output) in this NESUG paper: http://www.nesug.org/Proceedings/nesug11/po/po01.pdf

                          

  Also, I don't understand why you have aliases for HEIGHT and WEIGHT...where you have them now, they will represent the sum of all the heights/weights on every row, but it seems to me that you want VAR2 or a variable like VAR2 to be nested under each NAME. However, with NAME as an ACROSS item, if you want a computed variable nested under each unique value for NAME, you will have to 1) arrange your COLUMN statement differently and 2) use ABSOLUTE column numbers under each name.To test what your ABSOLUTE column numbers will look like, you can create an output dataset and then look at the column names that PROC REPORT creates for an ACROSS usage -- the program below has some suggested code changes. I took off NOPRINT and added OUT= and reduced the number of ACROSS items to just 4 names. I also created a new variable CALCVAR to go under each NAME value -- so you could see the difference between including CALCVAR in the nesting under NAME compared to VAR2, which is not nested under NAME.

  What you want to do is very do-able with PROC REPORT, but you have to understand ACROSS items and absolute column names to achieve your desired results. Carefully compare the PROC REPORT output to the PROC PRINT output for the created dataset. PROC PRINT shows you the absolute column numbers that REPORT assigns in an ACROSS usage situation. These are the internal column names that you would have to use in a COMPUTE block to do what you want under each NAME. In addition, you can see, by the value of _BREAK_ how the summary rows are being written by PROC REPORT and decide whether you really want both a BREAK and RBREAK in your final report.

   There have been many previous forum postings about using ACROSS items and nested variables under an ACROSS in a COMPUTE block. I would recommend that you review some of the previous forum postings on the topic of ACROSS usage with COMPUTE blocks and/or refer to the many user group papers on PROC REPORT for more information and examples.

cynthia

            

ods html file='origoutput.html' style=sasweb;

proc report data=sashelp.class nowd split='*'

            out=work.see_across_absolute;

                   

  title 'PROC REPORT using only 4 values for NAME';

  where name in ('Alfred', 'Alice', 'Barbara', 'Carol');

  column ('sex' sex) ('age' age)

         name ,( height  weight calcvar)

         ('HT' height=ht) ('WT' weight=wt) ('var2'  var2);

  define name / across '' ;

  define sex /  group '';

  define age /  analysis '';

  define height / sum analysis  ' ' ;

  define weight / sum analysis  ' ' ;

  define calcvar / computed ' ';

  define ht / analysis  '' ;

  define wt / analysis  ''  ;

  define var2 / computed " "

         style(column)={just=c protectspecialchars=off cellwidth=1.5in};

    

  compute calcvar / character length=75;

    _c5_ = 'absolute column 5';

    _c8_ = 'absolute column 8';

    _c11_ = 'absolute column 11';

    _c14_ = 'absolute column 14';

  endcomp; 

                    

  compute var2 / character length=75;

     var2 = catt(put(wt,5.0),'(',put(ht,5.1),')');

  endcomp;

              

break after sex /summarize;

rbreak after/ summarize dol dul;

run;

                                    

proc print data=work.see_across_absolute;

title 'what do absolute columns look like?';

run;

      

ods _all_ close;

   

title;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 675 views
  • 0 likes
  • 2 in conversation