DATA Step, Macro, Functions and more

How do I transform my data from table form to paragraph form?

Reply
Occasional Contributor
Posts: 5

How do I transform my data from table form to paragraph form?

I have a line list of cases that includes information like name, DOB, date of symptom onset, vaccination status, classification status, lab results, etc. I wan to take this information and get a print out of each of these fields per person with one person on each page. For example:

This

NameDOBDiseaseClassification statusMMR1 DateMMR2 DatePCR resultSerology result
John Doe10/25/1986MeaslesConfirmed10/25/198710/25/1994PositivePositive

Becomes this

Name: John Doe

DOB: 10/25/1986

Disease: Measles

Classification status: Confirmed

etc...

Having the column label in front of each value listed would be nice but not necessary. I can transpose data but this will not give me one page per person. Any ideas?

Thanks!

Super User
Posts: 10,483

Re: How do I transform my data from table form to paragraph form?

A very old school approach that may get you started:

data _null_;

     file "C:\path\myfilename.txt";

     set yourdatset;

     put "Name: " name /

          "DOB: " dob /

          "Disease: " disease      ;

    put _page_;

run;

You want to specify the path and name to somewhere you like. This creates a basic text document such as Notepad or other text editor can use.

Respected Advisor
Posts: 3,777

Re: How do I transform my data from table form to paragraph form?

Applying some of the new school functions to the old school method.


4-16-2014 6-33-12 AM.png



filename FT15F001 temp;
proc import datafile=FT15F001 out=info replace dbms=csv;
   parmcards;
Name,DOB,Disease,Classification status,MMR1 Date,MMR2 Date,PCR result,Serology result
John Doe,
10/25/1986,Measles,Confirmed,10/25/1987,10/25/1994,Positive,Positive
Jane Doe,
10/25/1986,Measles,Confirmed,10/25/1987,10/25/1994,Positive,Positive
;;;;
   run;

data _null_;
  
set info;
   by name notsorted;
  
put _page_;
  
do while(1);
      length _NAME_ $32 _LABEL_ _VALUE_ $128;
     
call vnext(_name_);
      if _name_ eq: 'FIRST.' then leave;
      _label_ = vlabelx(_name_);
      _value_ = left(vvaluex(_name_));
     
put _label_ +(-1) ': ' _value_;
      end;
  
run;



Contributor SKK
Contributor
Posts: 35

Re: How do I transform my data from table form to paragraph form?

Hi,

If you want to create a dataset this might help you-

PROC transpose data=Have out=want ;

VAR name DOB Disease Classification_status .... ;

BY name;

RUN;

If you want to create a report with one subject per page try this- 

I have used ODS statement to create a PDF report,

ods pdf file="\Report.pdf";


proc print data=new noobs;
by name notsorted;
pageby name;
run;

ods pdf close;

Super User
Posts: 9,671

Re: How do I transform my data from table form to paragraph form?

proc report also can get it and make it more beautiful .

Xia Keshan

Valued Guide
Posts: 2,174

Re: How do I transform my data from table form to paragraph form?

proc forms

proc fsbrowse

Super User
Super User
Posts: 7,392

Re: How do I transform my data from table form to paragraph form?

How about (and yes, you are limited to 10 titles, though with split char/rtf codes etc. you can make more):

data have;
  attrib Name DOB Disease Classification status MMR1 TDate MMR2 Date PCR result Serology result format=$20.;
  infile datalines delimiter=',' missover;
  input Name $ DOB $ Disease $ Classification $ status $ MMR1 $ TDate $ MMR2 $ Date $ PCR $ result $ Serology $ result;
datalines;
John Doe,10/25/1986,Measles,Skin,Confirmed,10/25/1987,10/25/1994,Positive,Positive,01/01/2013,AAA,1234,Positive,112233
John Doe,10/25/1986,Measles,Skin,Confirmed,10/25/1987,10/25/1994,Positive,Negative,02/01/2013,ABA,44234,Positive,445566
;
run;

proc sql;
  create table LOOP as
  select  distinct 
          NAME,
          DOB,
          DISEASE,
          CLASSIFICATION,
          STATUS,
          MMR1
  from    WORK.HAVE;
quit;


ods _all_ close;
ods pdf file="s:\temp\rob\test.pdf" style=statistical;
data _null_;
  set loop;
  call execute('title1 j=l "Name: '||strip(name)||'";
                title2 j=l "DOB: '||strip(dob)||'";
                title3 j=l "Disease: '||strip(disease)||'";
                title4 j=l "Classification: '||strip(classification)||'";
                title5 j=l "Status: '||strip(status)||'";
                title6 j=l "MMR1: '||strip(mmr1)||'";');
  call execute('proc print data=have (where=(name="'||strip(name)||'")) noobs;
                  var tdate mmr2 date pcr result serology;
                run;');
run;
ods _all_ close;

Respected Advisor
Posts: 3,777

Re: How do I transform my data from table form to paragraph form?

you might be interested in Substituting BY Line Values in a Text String



options byline=0;
proc print noobs;
  
by name dob disease classification status mmr1 notsorted;
  
title1 j=l '#byvar1: #byval1'
         
j=l '#byvar2: #byval2'
         
j=l '#byvar3: #byval3'
         
j=l '#byvar4: #byval4'
         
j=l '#byvar5: #byval5'
         
j=l '#byvar6: #byval6';
  
var tdate mmr2 date pcr result serology;  
  
run;
options byline=1;
Ask a Question
Discussion stats
  • 7 replies
  • 325 views
  • 1 like
  • 7 in conversation