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

I have a data set that need to be updated. 
Id 
89
180
2003
39123
I need to create a new string var "Unique_A200_2018" based on the id# and A200_2018. So, for id 89, his new Unique_A200_2018 is A200_2018_89.  id 39123, the new Unique_A200_2018 is A200_2018_39123 and so on.
New in SAS world, please help. Thanks, Shirley.

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@Bintang18 wrote:

This is what I got. I know, I have to fix  var property, but how about the invalid argument. Did I miss something?

BTW, id is numeric

Thank you again.


WARNING: In a call to the CATT function, the buffer allocated for the result
was not long enough to contain the concatenation of all the arguments.
The correct result would contain 12 characters, but the actual result
might either be truncated to 1 character(s) or be completely blank,
depending on the calling environment. The following note indicates the
left-most argument that caused truncation.


NOTE: Argument 1 to function CATT('A200_2018_',78) at line 40 column 22 is
invalid.


@Bintang18

The CATT() function creates a string which you then assign to a variable (the variable left from the equal sign).

If this variable is not long enough to hold the generated string then you get a log message as above.

 

Add at the very beginning of your data step a LENGTH statement  defining a length long enough for the generated string.

data have;
  id=25;
run;

data want;
  length newvar $20;
  set have;
  newvar=catt('A200_2018_',id);
run;

 

View solution in original post

6 REPLIES 6
art297
Opal | Level 21

There's a function for that! e.g.:

data want;
  set have;
  Unique_A200_2018=catt('A200_2018_',id);
run;

Art, CEO, AnalystFinder.com

 

Bintang18
Obsidian | Level 7

This is what I got. I know, I have to fix  var property, but how about the invalid argument. Did I miss something?

BTW, id is numeric

Thank you again.


WARNING: In a call to the CATT function, the buffer allocated for the result
was not long enough to contain the concatenation of all the arguments.
The correct result would contain 12 characters, but the actual result
might either be truncated to 1 character(s) or be completely blank,
depending on the calling environment. The following note indicates the
left-most argument that caused truncation.


NOTE: Argument 1 to function CATT('A200_2018_',78) at line 40 column 22 is
invalid.

art297
Opal | Level 21

You haven't told us something, but I don't know what that something is. The following worked for me:

data have;
  input Id;
  cards; 
89
180
2003
39123
;

data want;
  set have;
  Unique_A200_2018=catt('A200_2018_',id);
run;

Art, CEO, AnalystFinder.com

 

ballardw
Super User

@Bintang18 wrote:

This is what I got. I know, I have to fix  var property, but how about the invalid argument. Did I miss something?

BTW, id is numeric

Thank you again.


WARNING: In a call to the CATT function, the buffer allocated for the result
was not long enough to contain the concatenation of all the arguments.
The correct result would contain 12 characters, but the actual result
might either be truncated to 1 character(s) or be completely blank,
depending on the calling environment. The following note indicates the
left-most argument that caused truncation.


NOTE: Argument 1 to function CATT('A200_2018_',78) at line 40 column 22 is
invalid.


Did you copy and paste code from the forum? If the code is not in a code box, such as this opened with the {I}

something = CATT('A200_2018_',var);

or the box from the "running man" icon:

 

something = CATT('A200_2018_',var);

 

you might have accidentally picked up some invisible html or similar code. If you did copy/paste then try deleting the line of code and retyping.

I ran into one example on this site where a block of datalines had about one instance of "hidden" characters per line. Went through a lot of run the data step, read the errors, retype a data value. Repeat. The editor did not give any indication what those values might have been, there were "invisible" as far as the editor was concerned.

Patrick
Opal | Level 21

@Bintang18 wrote:

This is what I got. I know, I have to fix  var property, but how about the invalid argument. Did I miss something?

BTW, id is numeric

Thank you again.


WARNING: In a call to the CATT function, the buffer allocated for the result
was not long enough to contain the concatenation of all the arguments.
The correct result would contain 12 characters, but the actual result
might either be truncated to 1 character(s) or be completely blank,
depending on the calling environment. The following note indicates the
left-most argument that caused truncation.


NOTE: Argument 1 to function CATT('A200_2018_',78) at line 40 column 22 is
invalid.


@Bintang18

The CATT() function creates a string which you then assign to a variable (the variable left from the equal sign).

If this variable is not long enough to hold the generated string then you get a log message as above.

 

Add at the very beginning of your data step a LENGTH statement  defining a length long enough for the generated string.

data have;
  id=25;
run;

data want;
  length newvar $20;
  set have;
  newvar=catt('A200_2018_',id);
run;

 

Bintang18
Obsidian | Level 7
Thank you all for helping me out, it worked after I edit var length. Shirley

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
  • 6 replies
  • 836 views
  • 0 likes
  • 4 in conversation