03-29-2017 01:22 PM - edited 03-29-2017 01:23 PM
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;
03-29-2017 01:25 PM
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...
03-29-2017 01:28 PM
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 ;
03-29-2017 01:45 PM
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.
03-29-2017 01:59 PM
I'm not sure I follow. What I think you have is the following:
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?
03-29-2017 04:20 PM
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
03-29-2017 05:02 PM
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:
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.