Deriving labels or all possible formatted values of the variable to the list

Accepted Solution Solved
Reply
Contributor
Posts: 30
Accepted Solution

Deriving labels or all possible formatted values of the variable to the list

Let's say I have defined a format: 

 

PROC FORMAT;
VALUE myFormat
    1='Title 1'
    2='Title 2'
    3='Title 3'

;

Is it possible to create a list, e.g., 

 

%let ttls = Title 1 | Title 2| Title 3;

 

where Title 1, Title 2 and Title 3 are values of myFormat? Is it possible in SAS? 

 

Thank you very much


Accepted Solutions
Solution
‎12-03-2015 01:31 PM
Frequent Contributor
Posts: 85

Re: Deriving labels or all possible formatted values of the variable to the list

This will do the job:

/* Output the format details to a data set */
proc format fmtlib cntlout=myformat;
    select myformat;
run;
proc sql noprint;
    select label into :ttls separated by '|' from myformat;
quit;

%put &=ttls;

 

Depending on your situation, it is often better to keep the data for formats in data sets, which become the source from which you can generate the format, using PROC FORMAT  CNTLIN=...

 

You could then interrogate your source data set directly, rather than extracting the details first with the CNTLOUT=  option.

 

Hope this helps.

  

View solution in original post


All Replies
Solution
‎12-03-2015 01:31 PM
Frequent Contributor
Posts: 85

Re: Deriving labels or all possible formatted values of the variable to the list

This will do the job:

/* Output the format details to a data set */
proc format fmtlib cntlout=myformat;
    select myformat;
run;
proc sql noprint;
    select label into :ttls separated by '|' from myformat;
quit;

%put &=ttls;

 

Depending on your situation, it is often better to keep the data for formats in data sets, which become the source from which you can generate the format, using PROC FORMAT  CNTLIN=...

 

You could then interrogate your source data set directly, rather than extracting the details first with the CNTLOUT=  option.

 

Hope this helps.

  

Contributor
Posts: 30

Re: Deriving labels or all possible formatted values of the variable to the list

Thank you very much

Super User
Super User
Posts: 7,720

Re: Deriving labels or all possible formatted values of the variable to the list

The question shold be, why on earth would you want to do that?  Titles could be a long string of characters, escape character sequences, special characters etc. All of which will break a macro variable.  

 

What is it your trying to do as to my mind this is not the way to achieve it.

Contributor
Posts: 30

Re: Deriving labels or all possible formatted values of the variable to the list

I would like to create a macro that will accept a segmentation variable and a data set as an input and will create a nice output table with statistical analysis by the segmentation variable. However, on a way – for creating a nice output table – I need to create several new variables, whose LABELS are identical to the format value of the original segmentation variable. Thank you for alerting me about possible troubles. I'll make sure I avoid them. 

Super User
Super User
Posts: 7,720

Re: Deriving labels or all possible formatted values of the variable to the list

Sorry, those terms don't really mean much to me.  Perhaps you can provide an example of what you mean.  If its a function then very often they have options for labelling, and they can use by group processing, so I am still not clear on the need for macros, macro variables etc.

Contributor
Posts: 30

Re: Deriving labels or all possible formatted values of the variable to the list

Thank you. I received the answer. But thank you for your reply.
Super User
Posts: 11,128

Re: Deriving labels or all possible formatted values of the variable to the list

You may want to investigate Call Execute. You place things in a data set and then call execute builds syntax to execute without many of the macro headaches.

🔒 This topic is solved and locked.

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

Discussion stats
  • 7 replies
  • 389 views
  • 3 likes
  • 4 in conversation