The SAS Output Delivery System and reporting techniques

Unicode text align ODS PDF

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Unicode text align ODS PDF

[ Edited ]

Hello,

I'm trying to use SAS Studio with ODS PDF and proc report to generate a report of a table, and currently I'm having issues with the style of the output but only for columns with a unicode check mark. All of my non-unicode columns are outputting correctly, but my check mark columns ("cmf_display" and "returned")  will not align to the center. Here is the section of code that should produce the output...

 

 

ods listing close;
ods noresults;
ods escapechar="~";
options nodate nonumber;
ods pdf file = "&cipath./RSchneider/Monthly Summary Automation Development/Output/&practice..pdf";
ods pdf text="~S={font=(Times,11pt,bold) textalign=center color=black}Practice Contact:";
ods pdf text="~S={font=(Times,11pt) textalign=center color=black}&contact.";
ods pdf text="~S={font=(Times,11pt) textalign=center color=black}&email.";

proc report data = out.final_report (where=(practice = "&practice."))
	style(hdr)=[foreground=&icpblue. font=("Times",11pt) background = white protectspecialchars=off fontweight=bold
	textalign=center verticalalign=center]
	style(column) = [cellpadding=1pt textalign=center];
	columns (color ("Date Sent" date_sent) ("Qtr" qtr) ("CMF" cmf_Display) ("Project" Practice_initiative)
		("Due Date" due_date) ("Returned" returned));

	/*Define the style elements for each column*/
	define color / noprint;
	define date_sent / display " " style = [cellwidth=1in background=white foreground=black protectspecialchars=off
		font=("Times",11pt) textalign=center verticalalign=middle];
	define qtr / display " " style = [cellwidth=1in background=white foreground=black protectspecialchars=off
		font=("Times",11pt,bold) textalign=center verticalalign=middle];
	define cmf_display / display " " style = [cellwidth=1in background=white foreground=black protectspecialchars=off
		font=("Times",11pt) textalign=center verticalalign=middle];
	define practice_initiative / display " " style = [cellwidth=1in background=white foreground=black protectspecialchars=off
		font=("Times",11pt) textalign=center verticalalign=middle];
	define due_date / display " " style = [cellwidth=1in background=white foreground=black protectspecialchars=off
		font=("Times",11pt) textalign=center verticalalign=middle];
	define returned / display " " style = [cellwidth=1in background=white foreground=black protectspecialchars=off
		font=("Times",11pt) textalign=center verticalalign=middle];

 

I have also attached an example of the output.


Output.PNG

Accepted Solutions
Solution
‎02-07-2017 12:50 PM
SAS Super FREQ
Posts: 8,743

Re: Unicode text align ODS PDF

Hi:

  Well, rather than muddy the issue with macro, and colors and the CALL DEFINE, I made some fake data and I simplified your code to get rid of the extraneous settings for foreground and background color.

--If you start with the PEARL style for PDF, the colors are black and white.

--I changed the style override string for ODS PDF TEXT= to be the newest (since 9.2 syntax).

--I used the full font name "Times New Roman" on my system, because I do not have a font called "Times", just "Times New Roman".

--When making the data, I used just the simple string ~{unicode 2714} (no quotes, no x) as shown where I make the data.

--Took out the foreground/background since they aren't needed with the PEARL style

-- changed HEADER color to purple just to show how overrides work

--used correct style(column)={...} on the DEFINE statements

 

Here is the output:

center_checkmark.png

 

and here's the program I used:


data final_report;
  length cmf_display returned $20;
  set sashelp.class(obs=3);
  cmf_display = '~{unicode 2714}';
  returned = cmf_display;
  date_sent = age;
  qtr = height;
  practice_initiative = weight;
  due_date = mdy(1,age,1984);
run;

ods escapechar="~";
options nodate nonumber;

** with PEARL style, default colors are black on white unless changed with an override;
ods pdf file = "c:\temp\testunicode_2714.pdf" startpage=no style=pearl;
ods pdf text= "~{style[font=('Times New Roman',11pt,bold) textalign=center] Practice Contact:}";
ods pdf text="~{style[font=('Times New Roman',11pt) textalign=center] somebody}";
ods pdf text="~{style[font=('Times New Roman',11pt) textalign=center]somebody@server.com}";

proc report data = final_report 
	style(hdr)=[foreground=purple font=("Times New Roman",11pt)  fontweight=bold
	            textalign=center verticalalign=center]
	style(column) = [cellpadding=1pt textalign=center];
	columns ( ("Date Sent" date_sent) ("Qtr" qtr) ("CMF" cmf_Display) ("Project" Practice_initiative)
		("Due Date" due_date) ("Returned" returned));

	/*Define the style elements for each column*/
	     
	define date_sent / display " " style(column) = [cellwidth=1in   
		font=("Times New Roman",11pt) textalign=center verticalalign=middle];
	define qtr / display " " style(column) = [cellwidth=1in  
		font=("Times New Roman",11pt,bold) textalign=center verticalalign=middle];
	define cmf_display / display " " style(column) = [cellwidth=1in   
		font=("Times New Roman",11pt) textalign=center verticalalign=middle];
	define practice_initiative / display " " style(column) = [cellwidth=1in   
		font=("Times New Roman",11pt) textalign=center verticalalign=middle];
	define due_date / display " " style(column) = [cellwidth=1in 
		font=("Times New Roman",11pt) textalign=center verticalalign=middle];
	define returned / display " " style(column) = [cellwidth=1in  
		font=("Times New Roman",11pt) textalign=center verticalalign=middle];
  compute before _page_ / style={fontweight=bold};
     line '1) Similar to posted code using Unicode 2714';
	 line 'For PDF, checkmark cell is not using center align';
  endcomp;
run;


proc report data = final_report 
	style(hdr)=[foreground=purple font=("Times New Roman",11pt) fontweight=bold
	            textalign=center verticalalign=center]
	style(column) = [cellpadding=1pt textalign=center];
	columns ( ("Date Sent" date_sent) ("Qtr" qtr) ("CMF" cmf_Display) ("Project" Practice_initiative)
		("Due Date" due_date) ("Returned" returned));

	/*Define the style elements for each column*/
	      
	define date_sent / display " " style(column) = [cellwidth=1in   
		font=("Times New Roman",11pt) textalign=center verticalalign=middle];
	define qtr / display " " style(column) = [cellwidth=1in   
		font=("Times New Roman",11pt,bold) textalign=center verticalalign=middle];
	define cmf_display / display " " style(column) = [cellwidth=1in  leftmargin=.5in  
		font=("Times New Roman",11pt) textalign=center verticalalign=middle];
	define practice_initiative / display " " style(column) = [cellwidth=1in   
		font=("Times New Roman",11pt) textalign=center verticalalign=middle];
	define due_date / display " " style(column) = [cellwidth=1in 
		font=("Times New Roman",11pt) textalign=center verticalalign=middle];
	define returned / display " " style(column) = [cellwidth=1in leftmargin=.5in  
		font=("Times New Roman",11pt) textalign=center verticalalign=middle];
  compute before _page_/ style={fontweight=bold};
     line '2) With LEFTMARGIN=.5in can move checkmark to middle of cell';
  endcomp;
run;
ods pdf close;

Hope this helps get you pointed to a solution.

 

cynthia

View solution in original post


All Replies
Super User
Posts: 17,905

Re: Unicode text align ODS PDF

What version of SAS Studio and SAS are you using?

 

 

New Contributor
Posts: 4

Re: Unicode text align ODS PDF

Hi Reeza,

I'm using SAS Studio 3.3 (Enterprise Edition) and I believe the SAS version is 9.4.

SAS Super FREQ
Posts: 8,743

Re: Unicode text align ODS PDF

You did not show how you create the checkmark character. What UNICODE character did you use? Also, you do NOT show how the COLOR item was created or is being used.

Nor did you send any data that someone could use to run your program?

Not sure why you are using PROTECTSPECIALCHARS=OFF -- typically, you only use that for RTF and HTML when you are inserting control strings into the output. But PDF does not have control strings and you do not need PROTECTSPECIALCHARS for ODS ESCAPECHAR.

cynthia



cynthia
New Contributor
Posts: 4

Re: Unicode text align ODS PDF

[ Edited ]

Thank you for the quick response and apologies for not including all of the applicable information. As you can probably tell, this code is a work in progress and adapted from another piece of code that was used to output RTF files, which is why the PROTECTSPECIALCHARS option was used. I have now removed that option from the code.

 

The variables where the checkmark character needs to appear simply uses the string "~{unicode '2714'x}", where applicable. I have attached the dataset that my code references.

 

I know it is probably not as dynamic as it could be, but I used compute blocks to assign the background color. Please see my entire updated macro below.

 

%macro monthly;

 /*Create dataset for looping through practices and for obtaining contact info*/
 proc sort data = out.final_report; by practice descending date_sent; run;
 proc sort data = out.final_report nodupkey out=practices; by practice; run;
 
 /*create number variable to count the practices*/
 data praccount;
  retain rank;
  rank = _n_;
  set practices (keep=practice email contact);
 run;
 
 proc sql noprint;
  select count(practice) into :count
  from praccount;
 quit;
 
 %let i=1;
 %do %while (&i <= /*&count.*/10);
 
 data _null_;
  set praccount;
  where rank = &i.;
  call symput('practice',strip(practice));
  call symput('contact',strip(contact));
  call symput('email',strip(email));
 run;
 
ods listing close;
ods noresults;
ods escapechar="~";
options nodate nonumber;
ods pdf file = "&cipath./RSchneider/Monthly Summary Automation Development/Output/&practice..pdf";

 

 ods pdf text="~S={font=(Times,14pt,bold) textalign=center color=black}&Practice.";
 ods pdf text="~S={font=(Times,11pt,bold) textalign=center color=black}Practice Contact:";
 ods pdf text="~S={font=(Times,11pt) textalign=center color=black}&contact.";
 ods pdf text="~S={font=(Times,11pt) textalign=center color=black}&email.";
 ods pdf text="~S={font=(Times,11pt,bold) textalign=center color=black}Date Report Created: &sysdate9.";


 proc report data = out.final_report (where=(practice = "&practice."))
  style(hdr)=[foreground=&icpblue. font=("Times",11pt) background = white fontweight=bold
   textalign=center verticalalign=center]
  style(column) = [cellpadding=1pt textalign=center ];
   
  columns (color ("Date Sent" date_sent) ("Qtr" qtr) ("CMF" cmf_Display) ("Project" Practice_initiative)
    ("Due Date" due_date) ("Returned" returned));
   
  /*Define the style elements for each column*/
  define color / noprint;
  define date_sent / display " " style = [cellwidth=1in  foreground=black font=("Times",11pt) textalign=center verticalalign=middle];
  define qtr / display " " style = [cellwidth=1in foreground=black font=("Times",11pt,bold) textalign=center verticalalign=middle];
  define cmf_display / display " " style = [cellwidth=1in foreground=black font=("Times",11pt) textalign=center verticalalign=middle];
  define practice_initiative / display " " style = [cellwidth=1in foreground=black font=("Times",11pt) textalign=center verticalalign=middle];
  define due_date / display " " style = [cellwidth=1in foreground=black font=("Times",11pt) textalign=center verticalalign=middle];
  define returned / display " " style = [cellwidth=1in foreground=black font=("Times",11pt) textalign=center verticalalign=middle];

   compute date_sent;
    if color = "Green" then
     call define (_COL_, "style", "style=[background=&reportgreen]");
    if color = "Yellow" then
     call define (_COL_, "style", "style=[background=&reportyellow]");
    if color = "Red" then
     call define (_COL_, "style", "style=[background=&reportred]");

   endcomp;
    compute qtr; 
     if color = "Green" then
     call define (_COL_, "style", "style=[background=&reportgreen]");
    if color = "Yellow" then
     call define (_COL_, "style", "style=[background=&reportyellow]");
    if color = "Red" then
     call define (_COL_, "style", "style=[background=&reportred]");      

  endcomp; 
   compute cmf_display;
    if color = "Green" then
     call define (_COL_, "style", "style=[background=&reportgreen]");
    if color = "Yellow" then
     call define (_COL_, "style", "style=[background=&reportyellow]");
    if color = "Red" then
     call define (_COL_, "style", "style=[background=&reportred]");   

  endcomp;
   compute practice_initiative;
    if color = "Green" then
     call define (_COL_, "style", "style=[background=&reportgreen]");
    if color = "Yellow" then
     call define (_COL_, "style", "style=[background=&reportyellow]");
    if color = "Red" then
     call define (_COL_, "style", "style=[background=&reportred]"); 
   endcomp;
   compute due_date;
    if color = "Green" then
     call define (_COL_, "style", "style=[background=&reportgreen]");
    if color = "Yellow" then
     call define (_COL_, "style", "style=[background=&reportyellow]");
    if color = "Red" then
     call define (_COL_, "style", "style=[background=&reportred]");    

  endcomp;
   compute returned;
    if color = "Green" then
     call define (_COL_, "style", "style=[background=&reportgreen]");
    if color = "Yellow" then
     call define (_COL_, "style", "style=[background=&reportyellow]");
    if color = "Red" then
     call define (_COL_, "style", "style=[background=&reportred]");   endcomp;
 run;
 
 ods pdf close;


      %let i = %eval(&i+1);
      %end;
     
%mend;

%monthly

Attachment
Solution
‎02-07-2017 12:50 PM
SAS Super FREQ
Posts: 8,743

Re: Unicode text align ODS PDF

Hi:

  Well, rather than muddy the issue with macro, and colors and the CALL DEFINE, I made some fake data and I simplified your code to get rid of the extraneous settings for foreground and background color.

--If you start with the PEARL style for PDF, the colors are black and white.

--I changed the style override string for ODS PDF TEXT= to be the newest (since 9.2 syntax).

--I used the full font name "Times New Roman" on my system, because I do not have a font called "Times", just "Times New Roman".

--When making the data, I used just the simple string ~{unicode 2714} (no quotes, no x) as shown where I make the data.

--Took out the foreground/background since they aren't needed with the PEARL style

-- changed HEADER color to purple just to show how overrides work

--used correct style(column)={...} on the DEFINE statements

 

Here is the output:

center_checkmark.png

 

and here's the program I used:


data final_report;
  length cmf_display returned $20;
  set sashelp.class(obs=3);
  cmf_display = '~{unicode 2714}';
  returned = cmf_display;
  date_sent = age;
  qtr = height;
  practice_initiative = weight;
  due_date = mdy(1,age,1984);
run;

ods escapechar="~";
options nodate nonumber;

** with PEARL style, default colors are black on white unless changed with an override;
ods pdf file = "c:\temp\testunicode_2714.pdf" startpage=no style=pearl;
ods pdf text= "~{style[font=('Times New Roman',11pt,bold) textalign=center] Practice Contact:}";
ods pdf text="~{style[font=('Times New Roman',11pt) textalign=center] somebody}";
ods pdf text="~{style[font=('Times New Roman',11pt) textalign=center]somebody@server.com}";

proc report data = final_report 
	style(hdr)=[foreground=purple font=("Times New Roman",11pt)  fontweight=bold
	            textalign=center verticalalign=center]
	style(column) = [cellpadding=1pt textalign=center];
	columns ( ("Date Sent" date_sent) ("Qtr" qtr) ("CMF" cmf_Display) ("Project" Practice_initiative)
		("Due Date" due_date) ("Returned" returned));

	/*Define the style elements for each column*/
	     
	define date_sent / display " " style(column) = [cellwidth=1in   
		font=("Times New Roman",11pt) textalign=center verticalalign=middle];
	define qtr / display " " style(column) = [cellwidth=1in  
		font=("Times New Roman",11pt,bold) textalign=center verticalalign=middle];
	define cmf_display / display " " style(column) = [cellwidth=1in   
		font=("Times New Roman",11pt) textalign=center verticalalign=middle];
	define practice_initiative / display " " style(column) = [cellwidth=1in   
		font=("Times New Roman",11pt) textalign=center verticalalign=middle];
	define due_date / display " " style(column) = [cellwidth=1in 
		font=("Times New Roman",11pt) textalign=center verticalalign=middle];
	define returned / display " " style(column) = [cellwidth=1in  
		font=("Times New Roman",11pt) textalign=center verticalalign=middle];
  compute before _page_ / style={fontweight=bold};
     line '1) Similar to posted code using Unicode 2714';
	 line 'For PDF, checkmark cell is not using center align';
  endcomp;
run;


proc report data = final_report 
	style(hdr)=[foreground=purple font=("Times New Roman",11pt) fontweight=bold
	            textalign=center verticalalign=center]
	style(column) = [cellpadding=1pt textalign=center];
	columns ( ("Date Sent" date_sent) ("Qtr" qtr) ("CMF" cmf_Display) ("Project" Practice_initiative)
		("Due Date" due_date) ("Returned" returned));

	/*Define the style elements for each column*/
	      
	define date_sent / display " " style(column) = [cellwidth=1in   
		font=("Times New Roman",11pt) textalign=center verticalalign=middle];
	define qtr / display " " style(column) = [cellwidth=1in   
		font=("Times New Roman",11pt,bold) textalign=center verticalalign=middle];
	define cmf_display / display " " style(column) = [cellwidth=1in  leftmargin=.5in  
		font=("Times New Roman",11pt) textalign=center verticalalign=middle];
	define practice_initiative / display " " style(column) = [cellwidth=1in   
		font=("Times New Roman",11pt) textalign=center verticalalign=middle];
	define due_date / display " " style(column) = [cellwidth=1in 
		font=("Times New Roman",11pt) textalign=center verticalalign=middle];
	define returned / display " " style(column) = [cellwidth=1in leftmargin=.5in  
		font=("Times New Roman",11pt) textalign=center verticalalign=middle];
  compute before _page_/ style={fontweight=bold};
     line '2) With LEFTMARGIN=.5in can move checkmark to middle of cell';
  endcomp;
run;
ods pdf close;

Hope this helps get you pointed to a solution.

 

cynthia

New Contributor
Posts: 4

Re: Unicode text align ODS PDF

Adjusting the left margin of the column solved my problem. Thank you so much for your help Cynthia!!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 229 views
  • 0 likes
  • 3 in conversation