BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sanjay1
Obsidian | Level 7

Hi SAS experts,

am creating a macro "print" which is printing all the names in the dataset sashelp.class with titles.

But when am doing this in the ods pdf am not getting the titles for all the names, instead am getting the titles only for the first name.

Below is my code..please guide

 

 

step1--

%macro print;


proc sql noprint;
select count(distinct name) into:ct1 from sashelp.class;
quit;;


proc sql noprint;
select distinct name
into :name1-:name%sysfunc(compress(&ct1.))
from sashelp.class;
quit;

%do i=1 %to &ct1.;

title h=2 "each person info &&name&i.";
proc print data=sashelp.class;
where name="&&name&i.";
run;
%end;
%mend;

 

 step2--

%LET folder_path=path;


ods pdf file="path.pdf" startpage=no;

proc means data=sashelp.class;
class sex;
var height;
run;

ods pdf startpage=now;
%include "&folder_path.\print.sas";
%print;
ods pdf close;

 

Thanks & regards,

Sanjay.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi, I am not sure what you mean when you say that you want "Ods pdf text will be same per alll the pages but titles will be changed" -- it was my understanding from your original post that you wanted a title above the proc print for each NAME -- that string would become ODS TEXT, as shown here:

use_title_ods_text.png

 

Some variation of that should work for you. But in my example, the TITLE text goes with PROC MEANS, then gets turned off after MEANS and the ODS TEXT takes over (and looks like a TITLE because of the STYLE change) for every PROC PRINT.

 

cynthia

View solution in original post

7 REPLIES 7
sanjay1
Obsidian | Level 7

Hi SAS experts,

am creating a macro "print" which is printing all the names in the dataset sashelp.class with titles.

But when am doing this in the ods pdf am not getting the titles for all the names, instead am getting the titles only for the first name.

Below is my code..please guide

 

 

step1--

%macro print;


proc sql noprint;
select count(distinct name) into:ct1 from sashelp.class;
quit;;


proc sql noprint;
select distinct name
into :name1-:name%sysfunc(compress(&ct1.))
from sashelp.class;
quit;

%do i=1 %to &ct1.;

title h=2 "each person info &&name&i.";
proc print data=sashelp.class;
where name="&&name&i.";
run;
%end;
%mend;

 

 step2--

%LET folder_path=path;


ods pdf file="path.pdf" startpage=no;

proc means data=sashelp.class;
class sex;
var height;
run;

ods pdf startpage=now;
%include "&folder_path.\print.sas";
%print;
ods pdf close;

 

Thanks & regards,

Sanjay.

 

 

 

 

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Errm, not sure why your doing that, simply:

proc print data=sashelp.class;
  by name;
  title "The name is: #byval1";
run;

As always, macro is not a replacement for Base SAS.

Cynthia_sas
SAS Super FREQ

Hi, the other thing that might be causing a problem is your STARTPAGE option (although I agree with RW9 that you could use BY group processing and don't need a macro).

Your STARTPAGE=NOW is issuing 1 page "break" between PROC MEANS and the first PROC PRINT. but then the page breaks will stay off for everything else on the page. So essentially, you will only see a title for the first PROC PRINT that appears at the top of each page (if your output spans multiple pages). Known behavior of STARTPAGE is to suppress the title for every procedure but the first procedure on the page. This is why there is ODS TEXT ... if you really want some title text in between each output.

Or, the other thing you could try is STARTPAGE=YES before your %include and %PRINT macro.

Or here's an alternate BY group approach that shows the BYLINE above each table (not as a TITLE):

options byline;
ods pdf file='c:\temp\byvalprt.pdf' startpage=no;
  proc print data=sashelp.class;
   by name;
   title "Top Title";
  run;
ods pdf close;

bygroup_approach.png
cynthia

sanjay1
Obsidian | Level 7

Hi Cynthia,

 

That really helps me, is there is anyway to use both title and ods pdf text in one page..

Ods pdf text will be same per alll the pages but titles will be changed.

 

Thanks,

Sanjay.

Cynthia_sas
SAS Super FREQ

Hi, I am not sure what you mean when you say that you want "Ods pdf text will be same per alll the pages but titles will be changed" -- it was my understanding from your original post that you wanted a title above the proc print for each NAME -- that string would become ODS TEXT, as shown here:

use_title_ods_text.png

 

Some variation of that should work for you. But in my example, the TITLE text goes with PROC MEANS, then gets turned off after MEANS and the ODS TEXT takes over (and looks like a TITLE because of the STYLE change) for every PROC PRINT.

 

cynthia

sanjay1
Obsidian | Level 7

Thank you very much Cynthia.

sanjay1
Obsidian | Level 7

Hi Cynthia,

Is there is anyway to place the display of numbers right side or the left side of the map. (age 20-20 26-26 28-32 below the map, is there is anyway to palce it right side or left side of the map )

Below is my code

 

data response_data;
input idname$ X Y age;
cards;
Cuba -20722.00205 4678.3461646 20 24
Guatemala -21079.71903 4444.6666525 26
Haiti -20480.41176 4569.4493199 28
Honduras -20942.88097 4419.9807239 32
;
run;

proc template;
define style styles.colorramp;
parent=styles.pearl;
style twocolorramp / startcolor=cxF3F7FE endcolor=cx6497EB;
end;
run;
data anno;
length function style color $ 10 position $ 1 text $5;
retain flag 0 function 'label' xsys ysys '2' hsys '3' when 'a' ;
set response_data ;
color= 'black';
text=put(age,comma5.);
position = '5' ;
size = 2.5;
style = "Cumberland AMT";
output;
run;
proc gmap data=response_data map=mapsgfk.world;
id IDNAME;
choro age/annotate=anno coutline=grayaa xsize = 2 in ysize = 2 in;
run;
quit;

 

Thanks & Regards,

Sanjay

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
  • 7 replies
  • 3822 views
  • 1 like
  • 3 in conversation