I'm attemptine to merge several variables together and create a new merged variable for plotting. The simple concept is below.
data have;
set have;
merge varr1 var2 ... into varnew;
run';
proc sgplot data=have;
vbar varnew;
run;
New_Var = CoalesceC(var1, var2, var3);
The var1 var2 etc have the same format and length.
merging data sets uses a MERGE statement.
If you're trying to combine variables use a CAT type formula.
CATX() will concatenate variables with a delimiter, CATT() is another option.
Thanks for the quickk reply. Using the following code it does not seem to merge.
data have;
set have;
merge var1 var2 var3;
run;
How does the merge happen and where does it go? This should be a trivial operation. I need to merge/combine multiple variables of the same format and equal length for vbar plotting.
Also, I'm not clear on why the CAT's need to be used..
Thanks again.
It is trivial, I don't think you understand the MERGE statement. It's intended to merge DATA SETS not variables.
Post sample data if you need further assistance. CAT will combine variables into a single variable, which is what you seem to want. But it may not be the case, which is why you need to post data if you need further help.
new_variable= catt(var1, var2, var3);
Also, is merge the proper approach to this problem?
The input columns look like the below:
| 3 | ||
| 4 | ||
| 5 | ||
| 6 | ||
| 7 | ||
| 10 | ||
The desired output looks like
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
| 10 |
I hope this is clearer.
Best regards.
New_Var = CoalesceC(var1, var2, var3);
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.