applying a format and label from dataset

Accepted Solution Solved
Reply
Contributor
Posts: 66
Accepted Solution

applying a format and label from dataset

Hi,

If I have a dataset that shows the format to be applied to a variable name and another file that shows which label should go with a variable - is there a SAS procedure that can facilitate the application of the format and label?  This is similar to how one can create formats from a dataset using

proc format cntlin = Data_format ;

run ;

But instead of creating the format, I would like to apply the format and label.

This is the layout of the file associating each variable with a format:

name        format

Age          agrp.

Income     Incgrp.

etc

This is the layout of the file associating each variable with a label:

name                       label

Age                          Age group category

Income                     Income category

etc

I thought about using a macro and storing these in macro variable and then applying the formats and labels through proc datasets but there must be a more efficient way to do this.


Accepted Solutions
Solution
‎05-31-2013 06:11 PM
Super User
Super User
Posts: 7,042

Re: applying a format and label from dataset

Posted in reply to asishgautam

You will need to generate the code to apply the formats and labels. Either using macro variables or just writing the code yourself.  If the number of variables is small then just generate the code into a macro variables using PROC SQL.

proc sql ;

  select catx(' ',name,format) into :formats separated by ' ' from FORMATS ;

  select catx('=',name,quote(trim(label))) into :labels separated by ' ' from LABELS;

quit;

proc datasets nolist ;

  modify TARGET;

  format &formats;

  label &labels;

run;

quit;

View solution in original post


All Replies
Solution
‎05-31-2013 06:11 PM
Super User
Super User
Posts: 7,042

Re: applying a format and label from dataset

Posted in reply to asishgautam

You will need to generate the code to apply the formats and labels. Either using macro variables or just writing the code yourself.  If the number of variables is small then just generate the code into a macro variables using PROC SQL.

proc sql ;

  select catx(' ',name,format) into :formats separated by ' ' from FORMATS ;

  select catx('=',name,quote(trim(label))) into :labels separated by ' ' from LABELS;

quit;

proc datasets nolist ;

  modify TARGET;

  format &formats;

  label &labels;

run;

quit;

Contributor
Posts: 66

Re: applying a format and label from dataset

Thanks Tom.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 241 views
  • 0 likes
  • 2 in conversation