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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 445 views
  • 2 likes
  • 3 in conversation