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

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

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
MeganE
Pyrite | Level 9

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.

 

 

View solution in original post

17 REPLIES 17
ballardw
Super User

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.

 

 

MeganE
Pyrite | Level 9

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...]

MeganE
Pyrite | Level 9

Maybe proc report isn't the way to go??

Tim_SAS
Barite | Level 11

Couple of thoughts...

  1. Use LINE statements in a COMPUTE BEFORE block.
  2. Use ODS TEXT= or PROC ODSTEXT to create the text above.
  3. Create two PROC REPORT tables, the first one with the text above. Use ODS LAYOUT to print the tables with no space between them. You'll have to use some care to make both tables the same width.

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.

MeganE
Pyrite | Level 9

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.

Ksharp
Super User
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  ;


MeganE
Pyrite | Level 9

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.

 

 

 


ProcReport.png
ballardw
Super User

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;

MeganE
Pyrite | Level 9

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.

 

 

ballardw
Super User

@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

 

MeganE
Pyrite | Level 9

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.


ProcReport.png
Cynthia_sas
SAS Super FREQ
Hi, In addition to BallardW's suggestion just a few comments -- headline, headskip, wrap and width= are ignored by PDF, as they are LISTING only syntax.

In addition, generally for what you describe (a TABLE for each patient), many people would use COMPUTE BEFORE _PAGE_ as an alternative to BY group processing. I believe there are some previous postings that show the use of both methods of getting extra information on the report.

cynthia
MeganE
Pyrite | Level 9
Thanks, but i don't have the necessary foundation in proc report in order to be able to adapt code written for something else, for what i need to do.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 17 replies
  • 3509 views
  • 0 likes
  • 5 in conversation