Amadeus cookies policy - you'll see this message only once.

Amadeus use cookies on this website. They help us to know a little bit about you and how you use our website, which improves the browsing experience and marketing - both for you and for others. They are stored locally on your computer or mobile device. To accept cookies, continue browsing as normal. Or, go to the privacy policy for more information.

Vector-Valued Formats Using the SCAN Function

The drawback of using a format, rather than a dataset merge, is that you are only (in effect) adding one new column to your original dataset, rather than several. However, a little cunning can overcome this.

Let us take as an example the chemical elements, and suppose we want to associate with each atomic number the corresponding symbol, name, atomic weight, and a string describing a common use of the element.  

The trick is to concatenate all the properties into a single character string, using a suitable separator character such as “*”. Our format definition will read (in part):

proc format; 
  value property  
        … 

       38 = 'Sr*Strontium*87.62*glass for colour TV tubes' 
       39 = 'Y*Yttrium*88.9059*microwave oven filters' 
       40 = 'Zr*Zirconium*91.22*refractory material in glass/ceramics industries' 
       41 = 'Nb*Niobium*92.9064*arc-welding rods' 
       … 
       ;
run;  

After using the format, we can then use the SCAN function to extract the part of the string we need:

data_null_; 
  sym38=scan(put(38,property.),1,'*');
  nam39=scan(put(39,property.),2,'*');
  awt40=scan(put(40,property.),3,'*');
  use41=scan(put(41,property.),4,'*');
  put 'Element 38 has symbol ' sym38; 
  put 'Element 39 is called ' nam39;
  put 'Element 40 has atomic weight ' awt40; 
  put 'Element 41 is used for ' use41;
run;  

The output looks like this:

Element 38 has symbol Sr
Element 39 is called Yttrium
Element 40 has atomic weight 91.22
Element 41 is used for arc-welding rods