BookmarkSubscribeRSS Feed
gtucke1
Fluorite | Level 6

Hi,

 

I want to add a label to a variable in my data set. Below is what I've done. However, when I run the table for race and current_living_dich, the label "Current living situation" is not showing up. 

 

Data X;
Set Y;
Label
current_living_dich = "Current living situation";
Run;

 

Proc Format;
Value fmtrace 1 = 'White'
2 = 'Black'
3 = 'Asian'
4 = 'Other';
Value fmtcurrent_living_dich
0 = 'Living Alone'
1 = 'Living with ICP or Others';
Run;

Data X;
Set Y;
Format race fmtrace. current_living_dich fmtcurrent_living_dich.;
run;

Proc freq data = ICPNEED.data_carerecipients;
Tables race current_living_dich;
Run;

 

gtucke1_0-1653058133474.png

 

 

2 REPLIES 2
PaigeMiller
Diamond | Level 26

You have created data set X twice. First has the label. Then the second time you create it the label is not applied, and so doesn't exist in X. So ... don't do this. Create X once, assign the formats and labels in that data set.

 

Then there is an error here:

 

Proc freq data = ICPNEED.data_carerecipients;
Tables race current_living_dich;
Run;

 

The label is not in this data set.

--
Paige Miller
ballardw
Super User

You run Proc Freq against data set ICPNEED.data_carerecipients. The Label was added to the variable in the first data set X. Then you recreate the data set X without the label. So you 1) no longer have an any data set with the label and 2) create output from a completely different data set so would not have a chance of seeing the label.

 

IF the ONLY concern you have is a label you can add a LABEL statement to almost any procedure. That will override the default label assigned to the variable just for the duration of that procedure.

Such as:

Proc freq data = ICPNEED.data_carerecipients;
   Tables race current_living_dich;
   label current_living_dich ="Current living situation";
Run;

Note when you have two or more data steps with the same name on the DATA statement the result is only that of the last one. The previous version is completely replaced and not incorporated.

 

There is a procedure named DATASETS that will permanently modify things like variable names, formats and labels without using a data step. This procedure works by modifying the data set header information and does not require processing every record in a data set that a data step code uses. This can be pretty critical for time when data sets have millions of records as that would make a data step extremely inefficient for the purpose of adding a label or setting a default format.

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!

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
  • 580 views
  • 0 likes
  • 3 in conversation