BookmarkSubscribeRSS Feed
mariamon0
Fluorite | Level 6

I have a marriage variable called v1marital in one dataset and v_martial_0 in another.

I am trying to harmonize the variables and also change from character to numeric.

However, the variables have different conditions and I want vmarital=2 to equal 3 =v_marital_0. I'm not sure how to go about this.

V_MARITAL_0

1=single, never married

2=married, co-habituating

3=divorced or separated

4=widowed

and

V1MARITAL

1=single, never married

2=separate

3=divorced or annulled

4=widowed

5=married

 

1 REPLY 1
Kurt_Bremser
Super User

Keep as character.

Why? A number needs at least 3 bytes for storage, a single character just one.

Create a format that maps the 5 values to the 4 values:

proc format;
value $mconvert
  "1" = "1"
  "2" = "3"
  "3" = "3"
  "4" = "4"
  "5" = "2"
;
run;

Then you can use the put() function with the format for converting.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 400 views
  • 0 likes
  • 2 in conversation