<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: proc format cntlin in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/proc-format-cntlin/m-p/464505#M70512</link>
    <description>&lt;P&gt;Thank you ballardw for your reply. It makes sense. However, It didn't work after changing to&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;lookup = cats( form,put(isub,z2.));&lt;/PRE&gt;
&lt;P&gt;What does this piece of code do?&lt;/P&gt;
&lt;P&gt;RETURNED_VALUE = PUT(LOOKUP,$MATRIX.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The matrix format looks like this&lt;/P&gt;
&lt;P&gt;SAS Output&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.CNTL" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;Obs&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;FMTNAME&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;TYPE&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;HLO&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;START&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;LABEL&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="l data"&gt;MATRIX&lt;/TD&gt;
&lt;TD class="l data"&gt;C&lt;/TD&gt;
&lt;TD class="l data"&gt;O&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="l data"&gt;???&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="l data"&gt;MATRIX&lt;/TD&gt;
&lt;TD class="l data"&gt;C&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="l data"&gt;0101&lt;/TD&gt;
&lt;TD class="l data"&gt;001&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="l data"&gt;MATRIX&lt;/TD&gt;
&lt;TD class="l data"&gt;C&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="l data"&gt;0102&lt;/TD&gt;
&lt;TD class="l data"&gt;002&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;4&lt;/TH&gt;
&lt;TD class="l data"&gt;MATRIX&lt;/TD&gt;
&lt;TD class="l data"&gt;C&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="l data"&gt;0103&lt;/TD&gt;
&lt;TD class="l data"&gt;003&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="l data"&gt;MATRIX&lt;/TD&gt;
&lt;TD class="l data"&gt;C&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="l data"&gt;0104&lt;/TD&gt;
&lt;TD class="l data"&gt;004&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
    <pubDate>Wed, 23 May 2018 18:31:56 GMT</pubDate>
    <dc:creator>TX_STAR</dc:creator>
    <dc:date>2018-05-23T18:31:56Z</dc:date>
    <item>
      <title>proc format cntlin</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-format-cntlin/m-p/464459#M70505</link>
      <description>&lt;P&gt;Dear All,&lt;/P&gt;
&lt;P&gt;I created this format from an existing sas data set and use it to format another data set. However, it didn't&amp;nbsp;populate the correct numbers of columns that I suppose to have. Thanks so much.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA CNTL(KEEP=START LABEL FMTNAME TYPE HLO);&lt;BR /&gt; SET data1;&lt;BR /&gt; IF _N_ = 1 THEN DO;&lt;BR /&gt; FMTNAME = 'MATRIX';&lt;BR /&gt; TYPE = 'C';&lt;BR /&gt; HLO = 'O';&lt;BR /&gt; START = ' ';&lt;BR /&gt; LABEL = '???';&lt;BR /&gt; OUTPUT;&lt;BR /&gt; HLO = ' ';&lt;BR /&gt; RETAIN HLO FMTNAME TYPE;&lt;BR /&gt; END;&lt;BR /&gt; START = FORM || ITEM_SEQ;&lt;BR /&gt; LABEL = PUT(POSITION,Z3.);&amp;nbsp;&lt;BR /&gt; OUTPUT;&lt;BR /&gt;RUN; &lt;BR /&gt;PROC FORMAT CNTLIN=CNTL;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;------&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA&amp;nbsp;data3 (DROP=LOOKUP RETURNED_VALUE SLOT ISUB);&lt;BR /&gt; SET data2;&lt;BR /&gt; LENGTH M1-M&amp;amp;MATRIX_SLOTS. $ 1;&lt;BR /&gt; ARRAY ITEM (*) S1-S&amp;amp;ITEMS.;&lt;BR /&gt; ARRAY MATRIX (*) M1-M&amp;amp;MATRIX_SLOTS.;&lt;BR /&gt; DO ISUB = 1 TO &amp;amp;ITEMS.;&lt;BR /&gt; LOOKUP = FORM || PUT(ISUB,Z2.);&lt;BR /&gt; RETURNED_VALUE = PUT(LOOKUP,$MATRIX.);&amp;nbsp;&lt;BR /&gt; IF RETURNED_VALUE = '???' THEN DO;&lt;BR /&gt; FILE PRINT;&lt;BR /&gt; PUT '**** ERROR&amp;nbsp; ' LOOKUP=;&lt;BR /&gt; END;&lt;BR /&gt; ELSE DO; &lt;BR /&gt; SLOT = INPUT(RETURNED_VALUE,3.);&amp;nbsp;&lt;BR /&gt; MATRIX(SLOT) = ITEM(ISUB);&amp;nbsp;&lt;BR /&gt; END;&lt;BR /&gt; END;&lt;BR /&gt; OUTPUT;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;------------------log------------------------------------------------------&lt;/P&gt;
&lt;P&gt;416 DATA&amp;nbsp;data3&amp;nbsp;(DROP=LOOKUP RETURNED_VALUE SLOT ISUB);&lt;BR /&gt;417 SET data2;&lt;BR /&gt;418 LENGTH M1-M&amp;amp;MATRIX_SLOTS. $ 1;&lt;BR /&gt;SYMBOLGEN: Macro variable MATRIX_SLOTS resolves to 104&lt;BR /&gt;419 ARRAY ITEM (*)&lt;BR /&gt;419! S1-S&amp;amp;ITEMS.;&lt;BR /&gt;SYMBOLGEN: Macro variable ITEMS resolves to 30&lt;BR /&gt;420 ARRAY MATRIX (*)&lt;BR /&gt;420! M1-M&amp;amp;MATRIX_SLOTS.;&lt;BR /&gt;SYMBOLGEN: Macro variable MATRIX_SLOTS resolves to 104&lt;BR /&gt;421 DO ISUB = 1 TO &amp;amp;ITEMS.;&lt;BR /&gt;SYMBOLGEN: Macro variable ITEMS resolves to 30&lt;BR /&gt;422 LOOKUP = FORM || PUT(ISUB, Z2.);&lt;BR /&gt;423 RETURNED_VALUE = PUT(LOOKUP,$MATRIX.);&amp;nbsp;&lt;BR /&gt;424 IF RETURNED_VALUE = '???' THEN DO;&lt;BR /&gt;425 FILE PRINT;&lt;BR /&gt;426 PUT '**** ERROR&amp;nbsp; ' LOOKUP=;&lt;BR /&gt;427 END;&lt;BR /&gt;428 ELSE DO;&lt;BR /&gt;429 SLOT = INPUT(RETURNED_VALUE,3.);&amp;nbsp;&lt;BR /&gt;430 MATRIX(SLOT) = ITEM(ISUB);&amp;nbsp;&lt;BR /&gt;431 END;&lt;BR /&gt;432 END;&lt;BR /&gt;433 OUTPUT;&lt;BR /&gt;434 RUN;&lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 17:01:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-format-cntlin/m-p/464459#M70505</guid>
      <dc:creator>TX_STAR</dc:creator>
      <dc:date>2018-05-23T17:01:01Z</dc:date>
    </item>
    <item>
      <title>Re: proc format cntlin</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-format-cntlin/m-p/464491#M70509</link>
      <description>&lt;P&gt;I am not seeing&amp;nbsp;how&amp;nbsp;you expect a FORMAT to have anything to do with "the correct numbers of columns". A Format only controls how values are displayed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only place I see you using the format is in this line:&lt;/P&gt;
&lt;PRE&gt;RETURNED_VALUE = PUT(LOOKUP,$MATRIX.); &lt;/PRE&gt;
&lt;P&gt;How would that control the number of columns? Or is the returned value unexpected?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Be aware that this line:&lt;/P&gt;
&lt;PRE&gt;LOOKUP = FORM || PUT(ISUB,Z2.);&lt;/PRE&gt;
&lt;P&gt;may be creating values of LOOKUP different that you expect:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please consider this code:&lt;/P&gt;
&lt;PRE&gt;data example;
   input form $;
   isub= 4;
   lookup = form||put(isub,z2.);
datalines;
a
ab
abc
abcd
;
run;&lt;/PRE&gt;
&lt;P&gt;where lookup has differing numbers of spaces between the Form and the two digits.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps what you are looking for is&lt;/P&gt;
&lt;PRE&gt;   lookup = cats( form,put(isub,z2.));
&lt;/PRE&gt;
&lt;P&gt;which removes any trailing blanks from Form before appending the two digits.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 May 2018 17:18:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-format-cntlin/m-p/464491#M70509</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-05-25T17:18:34Z</dc:date>
    </item>
    <item>
      <title>Re: proc format cntlin</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-format-cntlin/m-p/464505#M70512</link>
      <description>&lt;P&gt;Thank you ballardw for your reply. It makes sense. However, It didn't work after changing to&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;lookup = cats( form,put(isub,z2.));&lt;/PRE&gt;
&lt;P&gt;What does this piece of code do?&lt;/P&gt;
&lt;P&gt;RETURNED_VALUE = PUT(LOOKUP,$MATRIX.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The matrix format looks like this&lt;/P&gt;
&lt;P&gt;SAS Output&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.CNTL" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;Obs&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;FMTNAME&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;TYPE&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;HLO&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;START&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;LABEL&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="l data"&gt;MATRIX&lt;/TD&gt;
&lt;TD class="l data"&gt;C&lt;/TD&gt;
&lt;TD class="l data"&gt;O&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="l data"&gt;???&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="l data"&gt;MATRIX&lt;/TD&gt;
&lt;TD class="l data"&gt;C&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="l data"&gt;0101&lt;/TD&gt;
&lt;TD class="l data"&gt;001&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="l data"&gt;MATRIX&lt;/TD&gt;
&lt;TD class="l data"&gt;C&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="l data"&gt;0102&lt;/TD&gt;
&lt;TD class="l data"&gt;002&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;4&lt;/TH&gt;
&lt;TD class="l data"&gt;MATRIX&lt;/TD&gt;
&lt;TD class="l data"&gt;C&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="l data"&gt;0103&lt;/TD&gt;
&lt;TD class="l data"&gt;003&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="l data"&gt;MATRIX&lt;/TD&gt;
&lt;TD class="l data"&gt;C&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="l data"&gt;0104&lt;/TD&gt;
&lt;TD class="l data"&gt;004&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 23 May 2018 18:31:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-format-cntlin/m-p/464505#M70512</guid>
      <dc:creator>TX_STAR</dc:creator>
      <dc:date>2018-05-23T18:31:56Z</dc:date>
    </item>
    <item>
      <title>Re: proc format cntlin</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-format-cntlin/m-p/464571#M70521</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;What does this piece of code do?&lt;/P&gt;
&lt;P&gt;RETURNED_VALUE = PUT(LOOKUP,$MATRIX.);&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the actual value of LOOKUP is "0101" then it writes the formatted value using the format, in this case "001" into the variable Returned_value. By default Returned_value would be a character variable. If not previously defined or had a length assigned it would have length as assigned the first time that line of code executes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What values do you have for "form" in your original data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are reasons we recommend providing some example data, preferably as a data step so can create a set to work with. And also provide what you expect for output.&lt;/P&gt;
&lt;P&gt;You have do loop that would result in only the value of Returned_value remaining in the data set of the last "item" examined.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It appears you are attempting to use someone else's code. I might suggest instead of building a format that you use to make a string value that is then used with an input to get the numeric value that you create an informat to create the numeric value from. A brief example with an intentional call to a value not provided which generates an error and diagnostics:&lt;/P&gt;
&lt;PRE&gt;proc format library=work;
   invalue matrix
'0101' = 1
'0102' = 2
'0103' = 3
other=_error_;
run;

data example;
   input form $;
   do i= 1 to 4;
      slot = input( cats(form,put(i,z2.) ),matrix. );
      output;
   end;
datalines;
01
;
run;&lt;/PRE&gt;
&lt;P&gt;You may have other issues related to the sizes of your arrays. The macro variable &amp;amp;items resolves to 40 and &amp;amp;Matrix_slots=104.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the largest number of matrix variables that would be assigned values in this case is likely 40 on any row of data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you get this code to work without any macro variables? With a data set data2 with only a few records and few variables to verify that the logic worked for a known case?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if the whole purpose of this is to find which element of an array has a specific value then there are two functions, depending on whether the value is numeric or character that will do that:&lt;/P&gt;
&lt;P&gt;slot = Whichc ('0101', of item(*) ); would return the first position of '0101' in the array item.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without a little more concrete as to what is actually in your data set, variable values and types and actual desired result I'm not sure what else I might be able to provide in the way of assistance.&lt;/P&gt;</description>
      <pubDate>Fri, 25 May 2018 17:17:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-format-cntlin/m-p/464571#M70521</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-05-25T17:17:34Z</dc:date>
    </item>
  </channel>
</rss>

