BookmarkSubscribeRSS Feed
gtucke1
Fluorite | Level 6

I've recoded the marriage variable to represent 1 = married and 0 = not remarried. How and where may I add a labels "married" and " not "married"? I also want to label edu_numeric as "CR Education"

 

Set ICPNEED.data_trim4;
edu_numeric = edu + 0;
If marriage = 1 then cr_marital = 1 "married";
Else
if marriage = 2 then cr_marital = 0 "not married";
Else
if marriage = 3 then cr_marital = 0;
Else
if marriage = 4 then cr_marital = 0;
Else
if marriage = 5 then cr_marital = 0;
Else
if marriage = . then cr_marital = .;
Label cr_marital = 'Care Recipient Marital Status';

Run;

2 REPLIES 2
Kurt_Bremser
Super User

Use a format to display 0/1 values as text:

data have;
input marriage;
datalines;
.
1
2
3
4
5
;

proc format;
value marital_status
  1 = "married"
  0 = "not married"
;
run;

data want;
set have;
if marriage in (2,3,4,5)
then cr_marital = 0;
else cr_marital = marriage; /* covers 1 and missing */
format cr_marital marital_status.;
label cr_marital = 'Care Recipient Marital Status';
run;

In your real data, assign the label for edu_numeric in the same way as for cr_marital.

BTW

edu_numeric = edu + 0;

is fully equivalent to

edu_numeric = edu;
Tom
Super User Tom
Super User

Labels are attached to variables (or also there a dataset labels).

So if you want to attach a label to CR_MARITAL that explains how it is coded you might do something like;

label cr_martial = 'Marriage status 1=Married 0=Not Married';

But I think what you are really looking is a way to display the VALUES in a special way.  That is what a FORMAT is for.

 

If you want a format that displays 1 as Married and 0 as Not Married then define a format that does that.

proc format;
value marital
  0='Not Married' 
  1='Married'
  other='Unkown'
;
run;

Then attach that format to any variable whose values you want to display that way.

format cr_marital marital.;

Note you can use the same format for as many variables that use the same coding.  For example if you a dataset that also had marital status for the parents you could the MARITAL format for those variables also.

 

Note that if you are coding a lot of binary variables it might just be easier to make a YESNO format instead and use it for all of them.

proc format ;
  value yesno 0='No' 1='Yes' ;
run;

proc freq data=have;
  tables married dead active ;
  format married dead active yesno.;
run;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 459 views
  • 0 likes
  • 3 in conversation