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

I am using ODS (prefer pdf or html, but can do rtf as well)  to output data and using a PUT statement within the ODS to the output information for each observation as a paragraph rather than listing the data in a table.

 

An example of the PUT statement within the ODS

 

 

 ods pdf file="&path.pdf";
 ods escapechar="^";
 data _null_;
   set have;
      file print ps=54 ls=97;
      ods text="^{style[font_face='calibri' fontsize=11pt just=center fontweight=bold] Report Header}";
	  hyperlink = 'C:\Documents'||substr(String,1,2)||'\'||substr(String,3,8)||'.pdf';
put / '@1 DocumentNumber $10. / @1 hyperlink / @1 ' Narrative: ' IncidentNarrative//; run; quit; ods pdf clos
ods listing; run;

 

 

Each paragraph in the output will be all the called variables for one observation/row. In each paragraph for each observation/row, I need to include a hyperlink that is unique for that one.

 

I've been struggling with this for a long time and am really hoping someone can help me figure this out.

 

Thanks for your time,

John

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

Like this?

ods html file="%sysfunc(pathname(WORK))\Output.html"; 
data _null;
  set HAVE;
  file print;
  HYPERLINK = cats(FILEPATH, '\', put(INJURYDATE,$4.), '\', OBSERVATIONID, '.pdf');
  HYPERLINK = cats('<a href="',  HYPERLINK,  '" target="_blank">', HYPERLINK, '</a>');
  put / @1 _N_ @10 'Observation: ' OBSERVATIONID    
      / @1 HYPERLINK                                
      / @1 'Age: ' AGE  'Sex: ' GENDER             
      / @1 ' Place of Injury: ' PLACEOFINJURY       
      / @1 '     Injury Date: ' INJURYDATE          
      / @1 ' Injury Location: ' CITY ', ' @34 STATE 
      / @1 '       Narrative: ' NARRATIVE         
      /;
run;
ods html close;

Capture.PNG

View solution in original post

6 REPLIES 6
ChrisNZ
Tourmaline | Level 20

I am unsure that I understand your need.

1. Can you provide running code please?

2. Can you provide a screenshot if the desired result (taken from a mock word processor document if you want)?

lynagh18
Fluorite | Level 6

Hi ChrisNZ,

 

The output that I'm going for is pictured below. Each observation and it's associated variables are formatted into a paragraph-like form. What I am trying to do is make the link in line 2 of each paragraph to be hyperlinked and have the hyperlinked file open in a new window/tab.

 

Output.PNG

Below is functioning code to get the above output (obviously you will have to replace the file paths with ones that work for you). I prefer html output b/c hyperlinks within pdfs seems to open hyperlinks in the same window, replacing the original output file you were on which is not what I want. I'd prefer if the hyperlinks open in new windows. Thanks so much for you help on this!

 

data test1; infile datalines dlm='#';
input FilePath & $28. ObservationID Gender $ Age Race & $17. PlaceOfInjury & $20. InjuryDate & $10. City & $20. State & $20. Narrative & $50.;
datalines;
C:\Users\Documents\Accidents# 123456# Male# 43# African American# Home# 2016-99-99# Unknown City# Unknown State# Male was injured in his home.#
C:\Users\Documents\Accidents# 123457# Female# 35# African American# Public Facility# 2019-99-99# Unknown City# Unknown State# Female was injured at a Public Facility.#
;
run;

/*OUTPUT DATA AS PDF*/
options pagesize=32767; /*page size set to max to avoid title repeating throughout and breaking up the output*/
   ods listing close;
   ods html file="C:\Users\Documents\Accidents\Ouput.html"; *nobookmarkgen style=styles.listing;

   data _null_;
      set test1;
      file print ps=54 ls=97;
      HyperLink = FilePath||'\'||substr(InjuryDate,1,4)||'\'||strip(ObservationID)||'.pdf';
  	put / @1 _n_ @10 'Observation: ' ObservationID /
		@1 Hyperlink  /
		@1 'Age: ' Age 'Sex: ' Gender 'Race:' Race /
		@1 ' Place of Injury: ' PlaceOfInjury /
		@1 '     Injury Date: ' InjuryDate /
		@1 ' Injury Location: ' City', ' @34 State /
		@1 '       Narrative: ' Narrative//;
   run;
   quit;

   ods html close;
   ods listing;

%put _user_; run;

 

ChrisNZ
Tourmaline | Level 20

Like this?

ods html file="%sysfunc(pathname(WORK))\Output.html"; 
data _null;
  set HAVE;
  file print;
  HYPERLINK = cats(FILEPATH, '\', put(INJURYDATE,$4.), '\', OBSERVATIONID, '.pdf');
  HYPERLINK = cats('<a href="',  HYPERLINK,  '" target="_blank">', HYPERLINK, '</a>');
  put / @1 _N_ @10 'Observation: ' OBSERVATIONID    
      / @1 HYPERLINK                                
      / @1 'Age: ' AGE  'Sex: ' GENDER             
      / @1 ' Place of Injury: ' PLACEOFINJURY       
      / @1 '     Injury Date: ' INJURYDATE          
      / @1 ' Injury Location: ' CITY ', ' @34 STATE 
      / @1 '       Narrative: ' NARRATIVE         
      /;
run;
ods html close;

Capture.PNG

lynagh18
Fluorite | Level 6

Thank you so much ChrisNZ!!!

 

This does work for me.

 

My original syntax for the hyperlink tags was not correct, but there was another seemingly unrelated issue that was preventing the hyperlinks from working. When I specified the page size (ps=) and line size (ls=) for the File Print statement, the hyperlink would be output as the literal string with the tags around it (e.g. <a href = link string> </a>) and wouldn't actually link/redirect to the other file. When I don't specify the page and line size for the File Print statement, the hyperlink is output and redirects as desired.

 

Thanks again.

 

ballardw
Super User

I think that what you are attempting is possible with Proc ODSTEXT. Note that is a specific proc not the ODS TEXT statement.

The procedure will take a data set as input, allows expressions in the P (stands for paragraph) statement and allows style overrides.

lynagh18
Fluorite | Level 6

Thanks for the response ballardw. I'm not quite sure what you mean, so I can't comment on whether this works or not, but given that ChrisNZ liked your response, I'm assuming yours is a valid solution. Thanks.

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