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);
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.