dataset name

Reply
Occasional Contributor
Posts: 7

dataset name

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

Super Contributor
Posts: 284

Re: dataset name

[ Edited ]

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;
Super Contributor
Posts: 284

Re: dataset name

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...

Valued Guide
Posts: 2,174

Re: dataset name

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 ;

 

Super Contributor
Posts: 284

Re: dataset name

Agree with @Peter_C

Valued Guide
Posts: 2,174

Re: dataset name

you should be able to engineer a loop generating the modify+label statements for each target table in each library that needs labelling
Occasional Contributor
Posts: 7

Re: dataset name

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.

Super Contributor
Posts: 284

Re: dataset name

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?

Esteemed Advisor
Posts: 7,293

Re: dataset name

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

 

 

Occasional Contributor
Posts: 7

Re: dataset name

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..

 

Grand Advisor
Posts: 10,210

Re: dataset name

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.

Ask a Question
Discussion stats
  • 10 replies
  • 161 views
  • 6 likes
  • 5 in conversation