BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
petlove
Obsidian | Level 7

I need add labels to many datasets. I can get these labels from datasets present in different library. can anyone help me regarding this?

1 ACCEPTED SOLUTION

Accepted Solutions
collinelliot
Barite | Level 11

You can use the sashelp.vcolumn data to pull the label information from one data set into a macro variable that you apply to both. 

 

The particular details of your data will depend on how similar the data truly are, but an example of doing this is as follows:

 

proc sql;
SELECT catx('=', name, quote(strip(label))) INTO :applyLabels SEPARATED BY ' '
FROM sashelp.vcolumn
WHERE libname = 'SASHELP' AND
              memname = 'CLASS';
quit;

data want;
set have;
label &applyLabels;
run;

View solution in original post

10 REPLIES 10
collinelliot
Barite | Level 11

You can use the sashelp.vcolumn data to pull the label information from one data set into a macro variable that you apply to both. 

 

The particular details of your data will depend on how similar the data truly are, but an example of doing this is as follows:

 

proc sql;
SELECT catx('=', name, quote(strip(label))) INTO :applyLabels SEPARATED BY ' '
FROM sashelp.vcolumn
WHERE libname = 'SASHELP' AND
              memname = 'CLASS';
quit;

data want;
set have;
label &applyLabels;
run;
collinelliot
Barite | Level 11

Note that this is a terrible example because sashelp.class does not have any labels on its variables, but you'll be replacing 'SASHELP' and 'CLASS' with a data set that in theory does have labels...

Peter_C
Rhodochrosite | Level 12

rather than apply these labels in a data step which rewrites the whole data, use the same label statement in

PROC DATASETS library= yourLib nolist ;
   modify your_data_set ;
     label &applyLabels ;
   run ;
quit ;

 

collinelliot
Barite | Level 11

Agree with @Peter_C

Peter_C
Rhodochrosite | Level 12
you should be able to engineer a loop generating the modify+label statements for each target table in each library that needs labelling
petlove
Obsidian | Level 7

Hi,

 

Thank you for your response.

If i use label statemt in datastep, it will search for variable and then apply label. howevr, we are more looking to get labels for dataset.

collinelliot
Barite | Level 11

I'm not sure I follow. What I think you have is the following:

 

data_no_labels

data_yes_labels

 

Where the variables are the same (or at least many are, but the code can be adapted to account for only common variables).

 

You want to use the sql code to pull the label information from "data_yes_labels" and then apply it to data_no_labels using the proc data sets.

 

Is that not correct?

 

As Peter said, if you have do this with a lot, you can generate some kind of a loop or possible write a macro. But without more details, it's hard to say. But first, is my description not correct?

art297
Opal | Level 21

Proc datasets can be used to change or add dataset labels as well. e.g.:

 

PROC DATASETS library= work nolist ;
  modify datasetname(label='Label for Data Set');
run ;

The question is how you have the two sets of datasetnames (i.e., the one with the labels and those that don't have labels or labels that you want to change.

 

If you have a file that includes both, it would be easy to wrap the above code into a macro.

 

Art, CEO, AnalystFinder.com

 

 

petlove
Obsidian | Level 7

Hi,

I need to label datasets not variables...but I kind of used similar approach you and peter mentioned. I got the labels for my datasets.

 

Thanka a lot..

 

ballardw
Super User

Do you mean you want to assign labels to variables in a data set using the labels that another dataset has assigned for the same variables?

 

If the data sets are exactly the same: number, name and type of varibles this may be the easiest way:

 

Data mydata;

    set

         OTHLIB.Data(obs=0)

         mydata

   ;

run;

 

Where OTHLIB.Data is the library and data set of the one you want to pull labels from (this will also get Formats and Informats),

and Mydata is the data set you want to have those attributes.

 

If you have a large number of sets to do this with better would be to get the bits you need from Dictionary.Columns or sashelp.vcolumn and use that information to call Proc Datasets to modify the data sets.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 10 replies
  • 1142 views
  • 6 likes
  • 5 in conversation