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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

7 REPLIES 7
mikki
Calcite | Level 5

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;

Tom
Super User Tom
Super User

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;

rajeshg
Calcite | Level 5

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,

Tom
Super User Tom
Super User

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;

rajeshg
Calcite | Level 5

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,

Tom
Super User Tom
Super User

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

rajeshg
Calcite | Level 5

Okie,,Got it,,

Thanks Tom for your valuable time..


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
  • 7 replies
  • 2429 views
  • 6 likes
  • 3 in conversation