BookmarkSubscribeRSS Feed
ANLYNG
Pyrite | Level 9

Hi,

 

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

 

Data could be like this:

 

Organisation, status

GGGG, N

YYYY, N

 

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

 

Organisaton, status

N GGGG,N

N YYYY,N

 

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

Like this :

 

CASE WHEN town=HH

THEN 'N'!!Organisation

END

 

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.

3 REPLIES 3
ballardw
Super User

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.

ANLYNG
Pyrite | Level 9

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

 

ballardw
Super User

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'
;
run;

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 624 views
  • 0 likes
  • 2 in conversation