I need add labels to many datasets. I can get these labels from datasets present in different library. can anyone help me regarding this?
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;
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;
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...
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 ;
Agree with @Peter_C
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.
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?
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
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..
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.
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!
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.