BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sspkmnd
Obsidian | Level 7
data da;
    length a $20;
    a = 'asd';
run;

proc sql noprint;
    update da set a = (select cats(max(age), '.') from sashelp.class);
    update da set a = (select substrn(cats(max(age), '.'), 1, 20) from sashelp.class);
    update da set a = (select substrn(cats(max(age), '.'), 1, 20) length=20 from sashelp.class);
    update da set a = substrn((select substrn(cats(max(age), '.'), 1, 20) length=20 from sashelp.class), 1, 20);
quit;

All statements above produce a warning about truncation. Does anyone know how to get rid of them?

 

Thanks & KR

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

You can avoid the $200 length by NOT using the cat family of functions. e.g.:

data da;
    length a $20;
    a = 'asd';
run;

proc sql noprint;
    update da set a = (select strip(put(max(age),2.))||'.' from sashelp.class)
/*     update da set a = (select substrn(cats(max(age), '.'), 1, 20) from sashelp.class) */
/*     update da set a = (select substrn(cats(max(age), '.'), 1, 20) length=20 from sashelp.class) */
/*     update da set a = substrn((select substrn(cats(max(age), '.'), 1, 20) length=20 from sashelp.class), 1, 20) */
  ;
quit;

Art, CEO, AnalystFinder.com

 

View solution in original post

3 REPLIES 3
HB
Barite | Level 11 HB
Barite | Level 11

 

 

If you do just

proc sql;
	create table a as
	select cats(max(age), '.') as myvar from sashelp.class;
quit;

by itself, and then look at the attributes of myvar you will see that it is $200, which is likely some sort of default length.

 

You can make the length of a in da longer or perhaps ALTER da with SQL.

 

 

EDIT:

 

this

data da;
    length a $220;
    a = 'asd';
run;

proc sql noprint;
    update da set a = (select cats(max(age), '.') from sashelp.class);
    update da set a = (select substrn(cats(max(age), '.'), 1, 20) from sashelp.class);
    update da set a = (select substrn(cats(max(age), '.'), 1, 20) length=20 from sashelp.class);
    update da set a = substrn((select substrn(cats(max(age), '.'), 1, 20) length=20 from sashelp.class), 1, 20);
quit;

proc sql;
	alter table da 
	modify a varchar(20); 
quit;

 

 doesn't throw any errors and may give you something to work with.

 

 

sspkmnd
Obsidian | Level 7
I need to use update with a subquery.
art297
Opal | Level 21

You can avoid the $200 length by NOT using the cat family of functions. e.g.:

data da;
    length a $20;
    a = 'asd';
run;

proc sql noprint;
    update da set a = (select strip(put(max(age),2.))||'.' from sashelp.class)
/*     update da set a = (select substrn(cats(max(age), '.'), 1, 20) from sashelp.class) */
/*     update da set a = (select substrn(cats(max(age), '.'), 1, 20) length=20 from sashelp.class) */
/*     update da set a = substrn((select substrn(cats(max(age), '.'), 1, 20) length=20 from sashelp.class), 1, 20) */
  ;
quit;

Art, CEO, AnalystFinder.com

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 3 replies
  • 10573 views
  • 0 likes
  • 3 in conversation