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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
7 REPLIES 7
capam
Pyrite | Level 9

The var1 var2 etc have the same format and length.

Reeza
Super User

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.

capam
Pyrite | Level 9

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.

Reeza
Super User

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);
capam
Pyrite | Level 9

Also, is merge the proper approach to this problem?

capam
Pyrite | Level 9

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.

Reeza
Super User
New_Var = CoalesceC(var1, var2, var3);

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
  • 7 replies
  • 1078 views
  • 0 likes
  • 2 in conversation