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

I have a variable which i had created by concatenating multiple other variables, but the text information within that variable in getting truncated and i had used the length of 2000 but of no use, i am still facing the same issue. Below is my code.

 

DATA FINAL2;
length message Message1-Message8 $2000;
set pre;
if SEX~=I_DM_SEX_TXT then Message1=compbl("Error: "||SEX||" <> "||I_DM_SEX_TXT||".");
if strip(vvalue(VISIT_DT))~=strip(vvalue(DSSTDAT_C)) then Message2=compbl("Error: "||VISIT_DT||" <> "||DSSTDAT_C||".");
if INDICATION~=I_STRATA_IND_TXT then Message3=compbl("Error: "||INDICATION||" <> "||I_STRATA_IND_TXT||".");
if strip(SUBTYPE)~=strip(I_C1_SUBT_TXT) then Message4=compbl("Error: "||SUBTYPE||" <> "||I_C1_SUBT_TXT||".");
if BASELINE_ANG_ATT_RATE~=I_STRATA_DRATE_TXT then Message5=compbl("Error: "||BASELINE_ANG_ATT_RATE||" <> "||I_STRATA_DRATE_TXT||".");
if SITE_NUMBER~=SITEMNEMONIC then Message6=strip(compbl("Error: "||SITE_NUMBER||" <> "||SITEMNEMONIC||"."));
if VISIT_TYPE~=EDC_VISIT_TYPE then Message7=strip(compbl("Error: "||VISIT_TYPE||" <> "||EDC_VISIT_TYPE||"."));
if SCREENING_NUM~=PATIENTNUMBER then Message8=strip(compbl("Error: "||SCREENING_NUM||" <> "||PATIENTNUMBER||"."));

MIS=STRIP(CATX(",",OF Message1-Message8));
IF MIS NE " " THEN message=STRIP(MIS); ELSE message=" ";
drop Message1-Message8;
if message ne "" ;
RUN;

 

Can someone tell me how to resolve this truncation issue.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

And where did you set the length of MIS? Nowhere. So it is defined per default with a length of 200.

See CATX Function :

In a DATA step, if the CATX function returns a value to a variable that has not previously been assigned a length, that variable is given a length of 200 bytes.

And that length is also returned by STRIP.

View solution in original post

8 REPLIES 8
andreas_lds
Jade | Level 19

Sorry, but the code is an unreadable mess. Please post formatted code.

Ravindra_
Quartz | Level 8
DATA FINAL2;
length message Message1 Message2 Message3 Message4 Message5 Message6 Message7 Message8 $2000.;
set pre;
if SEX~=I_DM_SEX_TXT then Message1=compbl("Error: "||SEX||" <> "||I_DM_SEX_TXT||".");
if vvalue(VISIT_DT)~=vvalue(DSSTDAT_C) then Message2=compbl("Error: "||VISIT_DT||" <> "||DSSTDAT_C||".");
if INDICATION~=I_STRATA_IND_TXT then Message3=compbl("Error: "||INDICATION||" <> "||I_STRATA_IND_TXT||".");
if strip(SUBTYPE)~=strip(I_STRATA_SUBT_TXT) then Message4=compbl("Error: "||SUBTYPE||" <> "||I_STRATA_SUBT_TXT||".");
if BASELINE_ANG_ATT_RATE~=I_STRATA_DRATE_TXT then Message5=compbl("Error: "||BASELINE_ANG_ATT_RATE||" <> "||I_STRATA_DRATE_TXT||".");
if SITE_NUMBER~=SITEMNEMONIC then Message6=compbl("Error: "||SITE_NUMBER||" <> "||SITEMNEMONIC||".");
if VISIT_TYPE~=EDC_VISIT_TYPE then Message7=compbl("Error: "||VISIT_TYPE||" <> "||EDC_VISIT_TYPE||".");
if SCREENING_NUM~=PATIENTNUMBER then Message8=compbl("Error: "||SCREENING_NUM||" <> "||PATIENTNUMBER||".");

MIS=STRIP(CATX(",",OF Message1-Message8));
IF MIS NE " " THEN message=STRIP(MIS); ELSE message=" ";
drop Message1-Message8;
if message ne "" ;
RUN;

The above is the code, truncation is happening with the variable "message"

Kurt_Bremser
Super User

And where did you set the length of MIS? Nowhere. So it is defined per default with a length of 200.

See CATX Function :

In a DATA step, if the CATX function returns a value to a variable that has not previously been assigned a length, that variable is given a length of 200 bytes.

And that length is also returned by STRIP.

Ravindra_
Quartz | Level 8
Thanks a lot for identifying this, it resolved my issue.
Kurt_Bremser
Super User

PS you do no need to strip the result of CATX, as CATX removes all leading and trailing blanks of all elements by itself; the receiving variable will be padded to its defined length as usual.

PaigeMiller
Diamond | Level 26

You probably ought to declare a length on MIS

 

If that's not it, then as I requested, show us a portion of the data that illustrates the problem, using the method I linked to (and not using any other method)

--
Paige Miller
Ravindra_
Quartz | Level 8
Thanks a lot for help, this had resolved the issue
PaigeMiller
Diamond | Level 26

We don't have your data, so we can't see the truncation you are seeing. Please provide a portion of your data following these instructions, and not by any other method.

 

DO NOT SKIP THIS STEP: please provide code in a SAS code by, by clicking on the "running man" icon and pasting your code into the window that appears. Your code is essentially unreadable as you have provided it.

--
Paige Miller

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 1350 views
  • 0 likes
  • 4 in conversation