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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 196 views
  • 2 likes
  • 2 in conversation