BookmarkSubscribeRSS Feed
shankerm
Calcite | Level 5


Hi

Can we use #byval for defining column names in proc report instead of using only in titles?

Thanks

8 REPLIES 8
Tom
Super User Tom
Super User

Perhaps you can format your report using the by variable as an across variable?

shankerm
Calcite | Level 5

Thanks Tom

But i am not doing across here. I am dividing my report into different parts using by statement..so across will not serve the purpose...

Cynthia_sas
SAS Super FREQ


Hi:

  I thought Tom's response was a good suggestion. Honestly, without seeing any data or code, it was really hard to imagine what you meant when you asked about using " #byval for defining column names in proc report". I just couldn't figure out how a BY variable would alter the column names in the report. Since the BY variable is used to determine page breaks -- thus dividing your report into different parts -- it is hard to visualize what you want. You can use a BY variable in PROC REPORT in your COLUMN statement -- so if you did by chance need to use the variable's value in a COLUMN, it would have to happen as part of the COLUMN statement. You may not actually need a BY variable at all in your PROC REPORT. However, without some kind of example of what you want and what you've tried, code-wise, it is nearly impossible to make a constructive suggestion.

cynthia

shankerm
Calcite | Level 5

/*Hi*/

/*Below is the code which i have tried.*/
/*In mail output for first report i want the column name(r3 ) to be displayed as 'F' and in */
/*second report i want it as 'M' but i am not able to get in mail. So please help.*/

DATA survey;
   INPUT id gender $ age inc r1 r2 r3 ;
   DATALINES;
1  F  35 17  7 2 2
17  M  50 14  5 5 3
33  F  45  6  7 2 7
49  M  24 14  7 5 7
65  F  52  9  4 7 7
81  M  44 11  7 7 7
2   F  34 17  6 5 3
18  M  40 14  7 5 2
34  F  47  6  6 5 6
50  M  35 17  5 7 5
;
run;
proc sort data=survey;
by gender;
run;

options nobyline;
filename smsmail email from = "<abcd@tyg.com>"
to = "test@abc.com"
subject="test"
CT = "TEXT/HTML";
ods _all_ close;
ODS LISTING CLOSE;
ODS HTML BODY = smsmail RS=NONE STYLE = NORMAL;
proc report data=survey;
column id gender  age inc r1 r2 r3 ;
by gender;
define r3/ '#byval1                                          ';
run;
ods html close;/*Hi*/

/*Below is the code which i have tried.*/
/*In mail output for first report i want the column name(r3 ) to be displayed as 'F' and in */
/*second report i want it as 'M' but i am not able to get in mail. So please help.*/

DATA survey;
   INPUT id gender $ age inc r1 r2 r3 ;
   DATALINES;
1  F  35 17  7 2 2
17  M  50 14  5 5 3
33  F  45  6  7 2 7
49  M  24 14  7 5 7
65  F  52  9  4 7 7
81  M  44 11  7 7 7
2   F  34 17  6 5 3
18  M  40 14  7 5 2
34  F  47  6  6 5 6
50  M  35 17  5 7 5
;
run;
proc sort data=survey;
by gender;
run;

options nobyline;
filename smsmail email from = "<abcd@tyg.com>"
to = "test@abc.com"
subject="test"
CT = "TEXT/HTML";
ods _all_ close;
ODS LISTING CLOSE;
ODS HTML BODY = smsmail RS=NONE STYLE = NORMAL;
proc report data=survey;
column id gender  age inc r1 r2 r3 ;
by gender;
define r3/ '#byval1                                          ';
run;
ods html close;

Tom
Super User Tom
Super User

Here is one way to use GENDER as an ACROSS variable above R3 to have the value of GENDER appear in the column heading.


data survey (index=(gender));

   input id gender $ age inc r1 r2 r3 @@;

cards;

1 F 35 17 7 2 2 17 M 50 14 5 5 3 33 F 45 6 7 2 7 49 M 24 14 7 5 7

65 F 52 9 4 7 7 81 M 44 11 7 7 7 2 F 34 17 6 5 3 18 M 40 14 7 5 2

34 F 47 6 6 5 6 50 M 35 17 5 7 5

run;

proc report data=survey nofs headline nocenter list;

  by gender;

  column id age inc r1 r2 gender,r3 ;

  define _all_ / order order=data ;

  define gender / across ' ';

  define r3 / display ' ';

run;

TITLE1

gender=F

                                                                 F

         id        age        inc         r1         r2

  ----------------------------------------------------------------

          1         35         17          7          2          2

         33         45          6          7          2          7

         65         52          9          4          7          7

          2         34         17          6          5          3

         34         47          6          6          5          6

TITLE1

gender=M

                                                                 M

         id        age        inc         r1         r2

  ----------------------------------------------------------------

         17         50         14          5          5          3

         49         24         14          7          5          7

         81         44         11          7          7          7

         18         40         14          7          5          2

         50         35         17          5          7          5



Cynthia_sas
SAS Super FREQ

Hi:

And, if you change Tom's COLUMN statement just a bit (just put r3,gender instead of gender,r3) , you can move the M or F down on the same header row with the other variables(because REPORT places headers in the order they occur in the COLUMN statement):

  column id age inc r1 r2 r3,gender ;

cynthia

shankerm
Calcite | Level 5

Thanks Tom and Cynthia

just one more thing, am using 'rbreak after'  as well for summarization in proc report but i am not able to get total for r3 column. Is there any solution for this..?

Cynthia_sas
SAS Super FREQ

Hi:

  I'd suggest you read about PROC REPORT and the DEFINE statement with the RBREAK statement. You have defined the usage of r3 to be DISPLAY usage. PROC REPORT considers that you do NOT want any summarizing to happen when you specify DISPLAY as the usage. The usage of SUM or ANALYSIS SUM (instead of DISPLAY) will allow PROC REPORT to summarize the R3 variable.

define r3 / sum ' ';

cynthia

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
  • 8 replies
  • 2890 views
  • 3 likes
  • 3 in conversation