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

I am trying to concatenate several variables that contain strings that are all in a format that starts with a number, then as a space, dash, space, and then some text.  For example, "200 - Example text".

 

No matter what I try, I'm only getting the number part to concatenate.

 

For example

 

FINAL = catx(', ', of Var1 - VAR3);

 

Is resulting in, "200, 1001, 1005" when it should be " 200 - Text, 1001 - Text, 1005 - Text".

 

Any help would be appreciated! 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

May be this is about formatted and internal values of a variable. Have a look at below and check if that is what's happening to you.

proc format;
  value sometext
    100='100 text a'
    200='200 text b'
    300='300 text c'
    ;
quit;

data sample;
  var1=100; var2=200; var3=300;
  format var1 var2 var3 sometext.;
  concat1=catx(',',var1,var2,var3);
  concat2=catx(',',put(var1,sometext.),put(var2,sometext.),put(var3,sometext.));
  output;
  stop;
run;

proc print data=sample;
run;

Capture.JPG

View solution in original post

5 REPLIES 5
Krueger
Pyrite | Level 9

Do you have sample data? 

 

is your example above VAR1 = 200, VAR2 = Example, VAR3 = Text?

 

Edit: It sounds like you just want to use CAT function not CATX?

Patrick
Opal | Level 21

May be this is about formatted and internal values of a variable. Have a look at below and check if that is what's happening to you.

proc format;
  value sometext
    100='100 text a'
    200='200 text b'
    300='300 text c'
    ;
quit;

data sample;
  var1=100; var2=200; var3=300;
  format var1 var2 var3 sometext.;
  concat1=catx(',',var1,var2,var3);
  concat2=catx(',',put(var1,sometext.),put(var2,sometext.),put(var3,sometext.));
  output;
  stop;
run;

proc print data=sample;
run;

Capture.JPG

Reeza
Super User
Concur with Patrick, you likely have a format on your data that is changing the value.
kryden
Calcite | Level 5

Thanks Patrick!

 

It was indeed a formatting issue.  As soon as I replaced var_name with put(var_name, format_name.) in the catx expression, I got what I was looking for.  

 

I suppose that this is what I get when trying to code after a very long day!

ballardw
Super User

What variable holds the text value(s)?

What variable holds the numeric value(s)?

 

I think that you need to show some actual values and the entire data step that you attempted.

 

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 5 replies
  • 815 views
  • 2 likes
  • 5 in conversation