Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>One handy feature of <code>proc format</code> is the ability to use a data set to create the format, instead of typing it in by hand. Your scenario seems like a perfect scenario for this feature.</p> <p>In the example you give, a few small changes to the "names" data set will put it in a form that can be read by proc format.</p> <p>For example, if I modify the names data set like so..</p> <pre><code>data names; retain fmtname "names" type "N"; input start end label $; datalines; 1 10 John 11 20 Paul 21 30 George 31 40 Ringo ; </code></pre> <p>I can then issue this command to build the format based on it.</p> <pre><code>proc format cntlin=names;run; </code></pre> <p>Now I can use this format just like you would with any other format. For example, to create a new column that contains the desired "name" based on the number, you could do this:</p> <pre><code>data numbers; input number; number_formatted=put(number,names.); datalines; 33 21 17 5 ; </code></pre> <p>Here is what the output would look like:</p> <pre><code> number_ number formatted 33 Ringo 21 George 17 Paul 5 John </code></pre> <hr> <p><strong>Update to address question:</strong></p> <p>There isn't much difference in coding needed to read from a text file. We just need to set it up so that the output data set has the particular variable names that proc format expects (fmtname, type, start, end , and label).</p> <p>For example, if I have an external comma-seperated file called "names.csv" that looks like this:</p> <pre><code>1,10,John 11,20,Paul 21,30,George 31,40,Ringo </code></pre> <p>Then I simply can change the code that creates the "names" data set so that it looks like this:</p> <pre><code>data names; retain fmtname "names" type "N"; infile "&lt;path to file&gt;/names.csv" dsd; input start end label $; run; </code></pre> <p>Now I can run proc format with the cntlin option like I did before:</p> <pre><code>proc format cntlin=names;run; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload