Hello,
Does anyone know how to use proc report and get text outside of the table? The output needs to (vaguely) look like this:
PATIENTS: Patient Profile
Contains one record per patient in the database, and gives basic demographic and related data.
Variable Type Length Format Comment
ADRIND num 8 This patient is included in the cohort
ADRINDTXT char 1 $ADRINDT. Reason this patient was not included in the cohort
BORN num 8 MMDDYY10. Date of Birth
[blah blah more meta data...]
************************
I have the table grid worked out, but not the text above it, which is three variables:
[name] : [Desc1]
[Desc2]
Here's the code i have so far:
ods listing close;
ods pdf file="&path.AppendixB.pdf";
proc report data=Formats3 nowd headline headskip wrap center;
column name desc1 desc2 variable type length format comment;
define variable / width=12 "Variable";
define type / width=9 "Type";
define length / width=16 "Length";
define format / width=254 "Format";
define comment / width=254 "Comment";
run;
ods pdf close;
Thanks
Megan
I really don't understand why no one seems to understand what my data source is or how i want the report to look. I thank you all for trying, i really do. But i'm closing this post. It's not helping at this point.
From your post I can't tell whether you want Proc Contents output as part of your report or not. Could you post an example of what you actually want this to look like. Dummy data is fine but since your question involves layout issues then we need an actual layout. An example dataset would also help to test code.
Also are the values you indicate with :
[name] : [Desc1]
[Desc2]
It may be that By group processing with Name Desc1 and Desc2 would work as there are some controls available for by values.
I did post what i want it to look like:
Using variable names, it's:
[name]: [desc1]
[desc2]
(Headers:) Variable Type Length Format Comment
[Variable] [Type] [Length] [Format] [Comment]
Output looks like:
PATIENTS: Patient Profile
Contains one record per patient in the database, and gives basic demographic and related data.
Variable Type Length Format Comment
ADRIND num 8 This patient is included in the cohort
ADRINDTXT char 1 $ADRINDT. Reason this patient was not included in the cohort
BORN num 8 MMDDYY10. Date of Birth
[blah blah more meta data...]
Maybe proc report isn't the way to go??
Couple of thoughts...
Also, those WIDTH= options don't work when you're creating PDF output. Instead, use the WIDTH= style attribute in a STYLE= option on the DEFINE statements.
Thanks, but it doesn't look like i can use variable names in the text.
I have three fields:
Name - dataset name
Desc1 - a short description of the dataset.
Desc2 - a longer description of the dataset.
I need the content of those three fields above each of the tables.
And thanks/sorry, but i have about 5 minutes experience with proc report. I don't know how to do a compute block or line statement or where to even put them in the code that i already have.
I just need to display the contents one dataset that contains table description information and proc contents info. And it's not looking like proc report is the best way for me to do it.
Not sure. What kind of report are you looking for ? Post a picture to display it . Maybe you need NAMED option : proc report data=Formats3 nowd headline headskip wrap center named ;
This is the current output. I created it through a data null with put statements. *If* it can be done through proc report, it might be easier. The put statements and word wrapping and junk is a p.i.t.a.
I'm trying to attach a photo. The words in red are the variable names from the dataset.
I can get variable, type, length, format, and comment through proc report, but i cannot get category, name, desc1, or desc2 in those positions.
Here is an approach that might help. Since the key bit appears to be that you have the name and descriptions about a data set in another set the code below:
1) creates an example data set to work with
2) creates a control dataset with some of the elements you describe
3) uses the control dataset to put the header elements before table output using Call Execute
4) uses existing SAS maintained meta data to extract the remainder of the data elements.
This approach would probably work best if your "comment" field actually is assigned as the variable label.
Data work.class;
set SASHELP.Class;
format age f2. height 4.1 weight 5.1 Sex $1. Name $10.;
Label
Age='Age at measure'
Height='Height in inches'
weight='Weight in pounds'
Sex = 'Gender'
Name= 'Student name'
;
run;
data RepControl;
informat dsname $32. libname $8. desc1 desc2 category $50.;
infile datalines dlm=',';
input dsname libname desc1 desc2 category;
dsname=upcase(dsname);
libname=upcase(libname);
datalines;
CLASS,Work,Student height and weight,Contains one record per student, Example Data
;
run;
ods pdf file="c:\somepath\trial.pdf";
data _null_;
set RepControl;
length str $ 200;
str= catx('"',"ODS Text=",Category,";");
Call Execute(str);
str = catx(": ",Dsname,Desc1);
str= catx('"',"ODS Text=",Str,";");
Call Execute(str);
str=catx('"',"ODS Text=",Desc2,";");
Call Execute(str);
Call Execute("Proc sql;");
Call Execute(" select Name Label='Variable',Type Label='Type',Length label='Length',");
Call Execute(" format Label='Format',Label Label='Comment'");
Call Execute(" from dictionary.columns");
str = cats(' where libname="',libname,'" and memname="',dsname,'"');
Call Execute(str);
call Execute(" order by Name;");
call execute("quit;");
run;
ods pdf close;
I really don't understand why no one seems to understand what my data source is or how i want the report to look. I thank you all for trying, i really do. But i'm closing this post. It's not helping at this point.
@MeganE wrote:
I really don't understand why no one seems to understand what my data source is or how i want the report to look. I thank you all for trying, i really do. But i'm closing this post. It's not helping at this point.
1) You did not post DATA we could test anything with so it is somewhat difficult to see what you are starting with
2) You show what appears to be the same item appearing multiple times and did not seem to understand we were trying to get clarification of the requirement
I posted a screen shot of the output with the data and variable names in red right there. I'll attach it again for you.
But I think that's part of the problem. I think people are assuming that "patient profile" is code for someone's name, but it's not. That the fields listed under variable actually contain data, but they ARE the data. The screenshot is verbatim what is in my dataset that i need to show up. It's one dataset with proc contents meta data for about 50+ tables.
I have one dataset with 9 fields in it and i need to place them all in a single report. That's it.
I don't see where "the same item appearing multiple times" is. I have 9 fields all with unique names.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: