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!
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;
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?
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;
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!
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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.