BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
mmkr
Quartz | Level 8

How do i assign page number in to macro varibale ?

proc sort data=sashelp.class out=class;
by age;
where age in (12,13,14);
run;

ods proclabel 'Report';
ods pdf startpage=yes;

/*I want to add page number variable into macro variable */
/*I want to reset pagenumber when ever new age starts in new page */
/*Basically I need two pagenumbers
one is full in order, other one is by age */

proc report data=class contents='' headline nowindows;by age;
columns name sex age height weight;

define name / display "Name";
define sex / display "Sex";
define age / group display "Age" ;
define height / display "Height";
define weight / display "Weight";
;

run;
ods pdf close;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

How would putting a page number into a macro variable help you?  What SAS code would use the macro variable to generate?

 

In general if you want to number the pages then you will need to know where the pages start in advance.  Which might be difficlut for a complicated report.  But if you are willing to risk a little more white space and really needed then just divide the data into pages and then use #BYVAL() to print the page number on the page.

 

Example:

proc sort data=sashelp.class out=class;
  by sex name;
run;
data class;
  set class;
  by sex;
  if first.sex then row=1;
  else row+1;
  page=ceil(row/5);
run;
ods pdf file="c:\downloads\pageby.pdf";
options nobyline;
title1 "Sex=#byval(sex) Page=#byval(page)";
proc print data=class;
  by sex page;
  pageby page;
run;
ods pdf close;

Tom_0-1719086800414.png

 

View solution in original post

3 REPLIES 3
mmkr
Quartz | Level 8

/*I want to add page number variable into macro variable */
/*I want to reset pagenumber when ever new age starts in new page */
/*Basically I need two pagenumbers
one is full in order, other one is by age */

Tom
Super User Tom
Super User

How would putting a page number into a macro variable help you?  What SAS code would use the macro variable to generate?

 

In general if you want to number the pages then you will need to know where the pages start in advance.  Which might be difficlut for a complicated report.  But if you are willing to risk a little more white space and really needed then just divide the data into pages and then use #BYVAL() to print the page number on the page.

 

Example:

proc sort data=sashelp.class out=class;
  by sex name;
run;
data class;
  set class;
  by sex;
  if first.sex then row=1;
  else row+1;
  page=ceil(row/5);
run;
ods pdf file="c:\downloads\pageby.pdf";
options nobyline;
title1 "Sex=#byval(sex) Page=#byval(page)";
proc print data=class;
  by sex page;
  pageby page;
run;
ods pdf close;

Tom_0-1719086800414.png

 

mmkr
Quartz | Level 8

Thanks so much , it's worked 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 413 views
  • 2 likes
  • 2 in conversation