Hello,
I would like to generate a PDF document that includes two pieces of information. Firstly, information about a variable (e.g., label, coding, items), and secondly, frequency tables. The challenge I'm facing is that I have multiple variables or variable stems (e.g., Var1), and for each of these variables, I want to create multiple frequency tables (e.g., Var1a, Var1b, Var1c). The issue I'm encountering is that I don't know how to report the corresponding frequency tables on the same page as the variable information for the variable stem (e.g., Var1). In the example code below, a PDF with 3 pages is generated, with the frequency tables (Var1a, Var1b, and Var1c) distributed across the 3 pages. However, I would like to print the three tables on page 1 alongside their variable stem (Var1) information. Does anyone know how I could structure the data and change my code so that I can report several proc report tables on one page/attach these tables to the variable information of the variable stem?
/* Data for Variable Information*/
data VariableInfo;
input Variable $ Beschriftung $ Kodierung $;
datalines;
Var1 Variable 10
Var2 Variable 20
Var3 Variable 30
;
/* Data for frequencies */
data ExampleData;
input ID Var1a Var1b Var1c;
datalines;
1 10 20 1
2 15 25 0
3 20 30 1
4 10 20 1
5 15 25 0
6 20 30 1
;
/* Generate frequencies and save them as separate tables */
%macro GenerateFrequencyTables;
%let varlist = Var1a Var1b Var1c;
%do i = 1 %to %sysfunc(countw(&varlist));
%let variable = %scan(&varlist, &i.);
proc freq data=ExampleData;
tables &variable / out=freqtable&variable;
run;
%end;
%mend GenerateFrequencyTables;
%GenerateFrequencyTables;
/* Macro for a pdf with Variable Info and frequency tables */
%macro ReportFrequencyTables;
ods pdf file="yourpath\ExampleFrequencyTables.pdf";
%let varlist = Var1a Var1b Var1c;
%let vari = Var1 Var2 Var3;
%do i = 1 %to %sysfunc(countw(&varlist));
%let variable = %scan(&varlist, &i.);
%let varinfo = %scan(&vari, &i.);
ods pdf startpage=now;
ods layout start width=19cm height=28cm;
proc report data=VariableInfo;
where Variable contains "&varinfo";
run;
proc report data=FreqTable&Variable;
column &variable COUNT PERCENT;
run;
ods layout end;
%end;
ods pdf close;
%mend ReportFrequencyTables;
%ReportFrequencyTables;
In case you are wondering why I am producing the frequency tables outside my ReportFrequencyTables Macro: That is because I am using (have to use) a predefined macro for frequencies in my report. But if it there is a solution that depends on generating the frequencies inside the ReportFrequencyTables macro, I will check if that is possible.
Kind regards
Assuming these two tables will fit on one page of your PDF file, you can use the option STARTPAGE=NO
Thank you for your reply! Unfortunately, I do not understand from the documentation where to put the ods startpage statement to receive the wanted result. Could you help me out and modify the code?
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.