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;
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;
/*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 */
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;
Thanks so much , it's worked
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!
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.
Ready to level-up your skills? Choose your own adventure.