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

Hi all,

 

I have two variables with the same information, its just one has the missing characters for the other. How do I merge them together to fill in the blanks?

 

For example;

ParkingSpot          Comments

1-11-21                     

                               1-12-22

1-13-23

 

I would like it to look like:

 

ParkingSpot

1-11-21

1-12-22

1-13-23

 

How do I achieve this outcome? CAT or Merge? 

 

Thanks 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Besides of coalescec() a simple condition would also do the job

if missing(parkingspot) then parkingspot=comments;

View solution in original post

3 REPLIES 3
ballardw
Super User

@EM_G wrote:

Hi all,

 

I have two variables with the same information, its just one has the missing characters for the other. How do I merge them together to fill in the blanks?

 

For example;

ParkingSpot          Comments

1-11-21                     

                               1-12-22

1-13-23

 

I would like it to look like:

 

ParkingSpot

1-11-21

1-12-22

1-13-23

 

How do I achieve this outcome? CAT or Merge? 

 

Thanks 

 


Does "comments" ever hold a value you do not want in the "Parkingspot" variable? And are the variables the same type?

If the answers above are "no" to the first and "yes" to the second then

 

Data want;
   set have;
   parkingspot= coalescec(parkingspot, comments);
run;

The Coalescec, and the similar for numeric values Coalesce, functions examine the list of values in quotes and returns the first non-missing value.

 

Merge is data set operation, not variables.

 

One of the CAT functions might work but if you ever have both variables with any values the result is likely to be a problem.

EM_G
Fluorite | Level 6
Thankyou for your helpful explanation. 'comments' hold some random values of no use, but where parkingspots is missing 'comments' has the values needed. If that makes sense.
Patrick
Opal | Level 21

Besides of coalescec() a simple condition would also do the job

if missing(parkingspot) then parkingspot=comments;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1030 views
  • 2 likes
  • 3 in conversation