Vatiable value truncating

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Vatiable value truncating

HI all,

I am using bellow code...everything is working perfectly except the actlevel variable..

Actlevel value truncating when Value is Total...it is displaying as "Tota"..

is there any way to avoid this truncation ??

Proc Report data=Sasuser.admit nowd out=qq;

Column Actlevel Sex Fee;

Define actlevel/Group format=$10.;

define sex/group;

define fee/analysis;

break after actlevel/summarize;

compute  actlevel;

If _break_ = "ActLevel" then

Actlevel="Total";

endcomp;

run;


Accepted Solutions
Solution
‎01-17-2014 12:47 AM
Super User
Super User
Posts: 7,059

Re: Vatiable value truncating

Make a NEW variable.

proc report data=sashelp.class nowd ;

  column sex sex2 age ;

  define sex/group noprint ;

  define sex2/group computed width=5 ;

  define age/analysis;

  break after sex/summarize;

  compute sex2 / character length=5 ;

    sex2=sex;

    if lowcase(_break_) = "sex" then sex2="total";

  endcomp;

run;

View solution in original post


All Replies
Occasional Contributor
Posts: 6

Re: Vatiable value truncating

Hi Rajesh,

     The truncation happens because in the original dataset  the lenght of actlevel variable is only $4. the format won't increase the length. The length of value 'Total' is 5 so the value will be truncated when trying to store that value to actlevel variable  only with length 4.

I just created another dataset just to set the value of ActLevel as $10. and used that data set as input to proc report... now the trnuncation issue resolved.

data admit;
   length ActLevel $10;
    set Sasuser.admit;
run;

Proc Report data=admit nowd out=qq;
   Column Actlevel Sex Fee;
   Define actlevel/Group format=$10.;
   define sex/group;
   define fee/analysis;

  break after actlevel/summarize;

  compute  actlevel;

      If _break_ = "ActLevel" then

        Actlevel="Total";

   endcomp;

run;

Super User
Super User
Posts: 7,059

Re: Vatiable value truncating

Most likely the variable ACTLEVEL is length $4.

For example try this program.

proc report data=sashelp.class nowd ;

  column sex age ;

  define sex/group format=$10.;

  define age/analysis;

  break after sex/summarize;

  compute sex;

    if lowcase(_break_) = "sex" then sex="total";

  endcomp;

run;

New Contributor
Posts: 4

Re: Vatiable value truncating

Yes,,,the value truncating just because of length of the variable.In Admit dataset length of the actlevel variable is 4.That is the reason only "Tota" is displaying.

so is there any way to increase the Actlevel variable length with in the Proc report instead of writing another datastep ??

Thanks,

Solution
‎01-17-2014 12:47 AM
Super User
Super User
Posts: 7,059

Re: Vatiable value truncating

Make a NEW variable.

proc report data=sashelp.class nowd ;

  column sex sex2 age ;

  define sex/group noprint ;

  define sex2/group computed width=5 ;

  define age/analysis;

  break after sex/summarize;

  compute sex2 / character length=5 ;

    sex2=sex;

    if lowcase(_break_) = "sex" then sex2="total";

  endcomp;

run;

New Contributor
Posts: 4

Re: Vatiable value truncating

Ahhh i see..

Thanks Tom..

But why don't SAS allow us to update the variable length with in the Procedure..I thought some options available in proc report like how we apply Format to particular variable.


Any how ,its working fine for me.

Thanks Again,

Super User
Super User
Posts: 7,059

Re: Vatiable value truncating

You can apply formats, but formats do not change the definition of the variable, just how they are displayed.

New Contributor
Posts: 4

Re: Vatiable value truncating

Okie,,Got it,,

Thanks Tom for your valuable time..


🔒 This topic is solved and locked.

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

Discussion stats
  • 7 replies
  • 353 views
  • 6 likes
  • 3 in conversation