DATA Step, Macro, Functions and more

user-defined format from a function

Frequent Contributor
Posts: 87

user-defined format from a function



Is there a simple way to make a format thar simply concatinate two char variables?


Data could be like this:


Organisation, status




I wish to use a format to the organisaton variable som I get this output:


Organisaton, status




Alternative set a constant value as a pre-fix on the organisation based on content in another variable.

Like this :



THEN 'N'!!Organisation



I can construct the code in different ways -  but i prefer to output the logic as a format so the original data not is changed and i do not need an extra column.


Any ideas??


Thanks in advance.

Super User
Posts: 13,946

Re: user-defined format from a function

Formats are associated with single variables, not multiple.


I think that you may want to provide a little more detail or variability in your "example" as you have n in 4 different places so it isn't exactly clear which 'n' goes where.


If you want to display 'GGGG' as a specific string that does not change then you could build a data set from your example values useing string concatenation functions so you have values like:

Start       label

GGGG     abc GGGG

YYYY       pd  YYYY

and build a format from that data set. There are some other bits. But a format only assings one label text to any given value.

You cannot have format assign abc GGGG one time and pd GGGG another time. That will require creating an actual additional variable with concatenation.

Frequent Contributor
Posts: 87

Re: user-defined format from a function

The organisation coloums has huge amount af different content. so I need to put a constant string or combine with another coloumn dynamiccaly. I was thinlking about a function and create a format from that - but is not sure how to do it...


Super User
Posts: 13,946

Re: user-defined format from a function

A format will only associate with a single variable. And only assign one output value for a given input (barring use of multilabel formats in the very small number of procedures that recognize them). Even though you can use a user function in a format it may only use one variable.


In effect you are asking to do something like this:

Proc format library=work;
value $junk
'GGGG' = 'abc GGGG'
'GGGG' = 'pd GGGG'

which will result in a repeated range error.


19   Proc format library=work;
20   value $junk
21   'GGGG' = 'abc GGGG'
22   'GGGG' = 'pd GGGG'
ERROR: This range is repeated, or values overlap: GGGG-GGGG.
23   ;
NOTE: The previous statement has been deleted.
24   run;
Ask a Question
Discussion stats
  • 3 replies
  • 2 in conversation