BookmarkSubscribeRSS Feed
staffordst
Calcite | Level 5

I want to indent a column based on the value of that column. This does not do it:

data t1;
length v1 $50;
v1='this is the text';
output;
v1='    this is the text';
output;
v1='z text';
output;
run;
proc report nowindows data=t1;
  columns v1;
  define v1/style=[indent=10];
  compute v1;
      if index(v1,'z') then
      call define(_col_, "style", 
                  "style=[backgroundcolor=yellow indent=10
                          fontfamily=helvetica 
                          fontweight=bold]");
   endcomp;
run;
2 REPLIES 2
Cynthia_sas
SAS Super FREQ

Hi:

When/if INDENT= does not work, you do have an alternative. LEFTMARGIN will sometimes work when INDENT= doesn't. For example, if you search for previous forum postings on LEFTMARGIN, I know I've posted a few examples. Here's one: https://communities.sas.com/message/121174 This is  also the kind of thing that Tech Support can help you with. The last example I posted illustrated with ODS TEXT, but if your PROC REPORT code is written correctly, you should be able to do indention....one way or another. I'm not at a computer with SAS right now, but I know that I have posted some code in the past.

The only thing is that putting leading spaces into your text string (as you show with one of the V1 values) will not normally work with ODS because leading blanks are typically ignored by ODS -- that's the purpose of LEFTMARGIN and INDENT. Also, for PROC REPORT, the correct style override is to indicate:

STYLE(COLUMN)={leftmargin=.5in}

instead of just STYLE= -- PROC REPORT needs an area in the DEFINE statement. You don't need one in the CALL DEFINE because you are only touching one possible place on the REPORT. But, as long as the STYLE override in the DEFINE is incorrect, you can't draw any conclusions about whether it's working or not working.

cynthia

Cynthia_sas
SAS Super FREQ

Hi:

  When I try the code below, in SAS 9.3, INDENT= does work for me. See the screenshot. If you don't get the same results when you try my code, then I'd suggest opening a track with Tech Support.

  I added and displayed a variable called ORDVAR, because I wanted to include a variable for INDENT=0 condition, so you could see that your INDENT=10 was working for most of the lines, then INDENT=50 was working for the line with 'z' and for the line that starts 'abc', indent value was set to 0.

cynthia

data t1;
length v1 $50;
ordvar = 1;
v1='this is the text';
output;
ordvar=2;
v1='    this is the text';
output;
ordvar=3;
v1='z text';
output;
ordvar=4;
v1='abcdefghij1234567890';
output;
run;
    
ods listing close;
ods pdf file='c:\temp\indent_leftmargin.pdf';
 
proc report data=t1 nowd;
  columns ordvar v1;
  define ordvar / order;
  define v1/display style(column)=[indent=10 cellwidth=2in];
  compute v1;
      if index(v1,'z') = 1 then do;
         call define(_col_, "style",
                     "style=[backgroundcolor=yellow indent=50
                             fontfamily=helvetica
                             fontweight=bold]");
     end;
     if index(v1,'abc') gt 0 then do;
         call define(_col_, "style",
                     "style=[backgroundcolor=cyan indent=0
                             fontfamily=helvetica
                             fontweight=bold]");
     end;
   endcomp;
run;

   
ods pdf close;


use_indent.png

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 2 replies
  • 13641 views
  • 4 likes
  • 2 in conversation