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

Hello!

 

I'm trying to generate a report to briefly show how a facility responded to a survey. I currently have my data in this format, where there are variables listing all questions that they provided that answer to. 

data have;
input fac_name $ ans_yes $ ans_no $ ans_always $ ans_sometimes $ ans_never $;
datalines;
"Facility A" "yes answers" "no answers" "always answers" "sometimes answers" "never answers"
"Facility B" "yes answers" "no answers" "always answers" "sometimes answers" "never answers"
;

I would like to generate a PDF report with a page that basically looks like this for each facility:

 

Facility Name: fac_name

Answered "yes": ans_yes

Answered "no": ans_no 

Answered "always": ans_always

Answered "sometimes": ans_sometimes

Answered "never": ans_never

 

Basically, on each line I would like a string of text (ex. 'Answered "yes"') followed by the value of the variable for that facility. I can only figure out how to provide output in a table format, is there a way to just print values of a variable to a PDF document like this? 

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Something that will look like that though technically is still a table.

data have;
   infile cards dsd dlm=' ';
   length fac_name $16;
   array ans $24 yes no always sometimes never;
   input (fac_name ans[*]) (:);
   datalines;
"Facility A" "yes answers" "no answers" "always answers" "sometimes answers" "never answers"
"Facility B" "yes answers" "no answers" "always answers" "sometimes answers" "never answers"
;;;;

proc odstext data=have;
   list;   
      item 'Facility Name: ' || fac_name;
      item 'Answered "yes": ' ||yes ;
      item 'Answered "no": ' ||no   ;
      item 'Answered "always": ' ||always;
      item 'Answered "sometimes": ' ||sometimes;
      item 'Answered "never": ' ||never   ;
   end;
;
run;

View solution in original post

6 REPLIES 6
data_null__
Jade | Level 19

 

 

ods pdf file='answers.pdf';
data have;
   file print;
   infile cards dsd dlm=' ';
   length fac_name $16;
   array ans $24 yes no always sometimes never;
   input (fac_name ans[*]) (:);
   put 'Facility name: ' fac_name;
   length Answered $16;
   do i = 1 to dim(ans);
      Answered = quote(vname(ans[i]));
      put answered= +(-1) ': ' ans[i];
      end;
   put;
   datalines;
"Facility A" "yes answers" "no answers" "always answers" "sometimes answers" "never answers"
"Facility B" "yes answers" "no answers" "always answers" "sometimes answers" "never answers"
;;;;
   run;
ods pdf close;

Capture.PNG

AhmedAl_Attar
Ammonite | Level 13

If you are interested in making the Report a bit fancy, you might want to look into the 

ODS Report Writing Interface  Check the examples section

http://support.sas.com/rnd/base/ods/Tipsheet_RWI.pdf

 

Hope this helps,

Ahmed

 

megsredl
Obsidian | Level 7
This is very helpful, thank you!
ballardw
Super User

Something that will look like that though technically is still a table.

data have;
   infile cards dsd dlm=' ';
   length fac_name $16;
   array ans $24 yes no always sometimes never;
   input (fac_name ans[*]) (:);
   datalines;
"Facility A" "yes answers" "no answers" "always answers" "sometimes answers" "never answers"
"Facility B" "yes answers" "no answers" "always answers" "sometimes answers" "never answers"
;;;;

proc odstext data=have;
   list;   
      item 'Facility Name: ' || fac_name;
      item 'Answered "yes": ' ||yes ;
      item 'Answered "no": ' ||no   ;
      item 'Answered "always": ' ||always;
      item 'Answered "sometimes": ' ||sometimes;
      item 'Answered "never": ' ||never   ;
   end;
;
run;
megsredl
Obsidian | Level 7
Thank you, PROC ODSTEXT is exactly what I was looking for!

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1907 views
  • 3 likes
  • 4 in conversation