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-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!

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