DATA Step, Macro, Functions and more

continue indent when text wraps

Accepted Solution Solved
Reply
Regular Contributor
Posts: 187
Accepted Solution

continue indent when text wraps

Hi all,

 

I have an rtf table with three levels of output indent values that need to look like this (2 spaces at each indent):

ATC Level 1 /

  ATC Level 2 /
    Generic Drug Name

 

 

One level of output looks like this.  I would like that last line of output to continue with the indent but it is wrapping back to the left.  

 

SENSORY ORGANS

  OPHTHALMOLOGICALS

    ASCORBIC ACID;CUPRIC OXIDE;DL-ALPHA TOCOPHERYL ACETATE; XANTOFYL; ZEAXANTHIN;ZINC OXIDE

 

 

my code looks like this:

 

if ord=1 then do;
name =strip(ATC01TXT);
end;
else if ord=2 then do;
name ='  ' || strip(ATC02TXT);
end;
else if ord=3 then do;
name ='    ' || strip(generic);
end;

 

Is there something I can add in the datastep to continue the indent when the text wraps?


Accepted Solutions
Solution
‎05-11-2018 12:13 PM
SAS Super FREQ
Posts: 9,434

Re: continue indent when text wraps

Hi:

  When I use some "helper" variables to indicate which level to indent, the wrapping works as you explain. Here's the fake data I made, with some "helper" variables called TYPVAR and ORDVAR:

fake_data_to_wrap.png

Indenting "spaces" doesn't really apply to a proportional font, so I used the LEFTMARGIN style override to force the indenting, based on the value of ORDVAR within each TYPVAR value.

 

results_using_leftmargin.png

I set the overall width of the column to 3in to ensure that the longest line (line 3) would wrap, and then set the LEFTMARGIN attribute based on the value of ORDVAR.

 

  Since you didn't say what destination you were interested in, I used RTF for this example. I used PROC REPORT to product a report table, since indenting in a dataset doesn't make sense.

 

  Here's the full code:

data fakedata;
  length typvar 8 ordvar 8 lineinfo $500;
  infile datalines dlm=',' dsd;
  input typvar ordvar lineinfo $;
return;
datalines4;
1,1,"SENSORY ORGANS"
1,2,"OPHTHALMOLOGICALS"
1,3,"ASCORBIC ACID;CUPRIC OXIDE;DL-ALPHA TOCOPHERYL ACETATE; XANTOFYL; ZEAXANTHIN;ZINC OXIDE"
2,1,"First Line"
2,2,"Second Line"
2,3,"Third Line is very long; and needs to be indented too; and now that's all."
;;;;
run;

ods rtf file='c:\temp\showindent.rtf';
proc report data=fakedata;
   column typvar ordvar lineinfo;
   define typvar / group noprint;
   define ordvar / order noprint;
   define lineinfo / 'Information'
          style(column)={width=3in};
   compute lineinfo;
      if ordvar =1 then do;
	    call define(_col_,'style','style={fontweight=bold leftmargin=0in}');
	  end;
	  else if ordvar=2 then do;
	    call define(_col_,'style','style={fontweight=bold leftmargin=.125in}');
	  end;
	  else if ordvar = 3 then do;
	    call define(_col_,'style','style={fontweight=bold leftmargin=.25in}');
	  end;
   endcomp;
run;
ods rtf close;




Hope this helps,

Cynthia

View solution in original post


All Replies
Super User
Posts: 13,942

Re: continue indent when text wraps

What ods destination are you sending output to? You may have to include destination specific codes as part of the values or table building code.

Solution
‎05-11-2018 12:13 PM
SAS Super FREQ
Posts: 9,434

Re: continue indent when text wraps

Hi:

  When I use some "helper" variables to indicate which level to indent, the wrapping works as you explain. Here's the fake data I made, with some "helper" variables called TYPVAR and ORDVAR:

fake_data_to_wrap.png

Indenting "spaces" doesn't really apply to a proportional font, so I used the LEFTMARGIN style override to force the indenting, based on the value of ORDVAR within each TYPVAR value.

 

results_using_leftmargin.png

I set the overall width of the column to 3in to ensure that the longest line (line 3) would wrap, and then set the LEFTMARGIN attribute based on the value of ORDVAR.

 

  Since you didn't say what destination you were interested in, I used RTF for this example. I used PROC REPORT to product a report table, since indenting in a dataset doesn't make sense.

 

  Here's the full code:

data fakedata;
  length typvar 8 ordvar 8 lineinfo $500;
  infile datalines dlm=',' dsd;
  input typvar ordvar lineinfo $;
return;
datalines4;
1,1,"SENSORY ORGANS"
1,2,"OPHTHALMOLOGICALS"
1,3,"ASCORBIC ACID;CUPRIC OXIDE;DL-ALPHA TOCOPHERYL ACETATE; XANTOFYL; ZEAXANTHIN;ZINC OXIDE"
2,1,"First Line"
2,2,"Second Line"
2,3,"Third Line is very long; and needs to be indented too; and now that's all."
;;;;
run;

ods rtf file='c:\temp\showindent.rtf';
proc report data=fakedata;
   column typvar ordvar lineinfo;
   define typvar / group noprint;
   define ordvar / order noprint;
   define lineinfo / 'Information'
          style(column)={width=3in};
   compute lineinfo;
      if ordvar =1 then do;
	    call define(_col_,'style','style={fontweight=bold leftmargin=0in}');
	  end;
	  else if ordvar=2 then do;
	    call define(_col_,'style','style={fontweight=bold leftmargin=.125in}');
	  end;
	  else if ordvar = 3 then do;
	    call define(_col_,'style','style={fontweight=bold leftmargin=.25in}');
	  end;
   endcomp;
run;
ods rtf close;




Hope this helps,

Cynthia

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 123 views
  • 1 like
  • 3 in conversation