<?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: Using informat when reading from other dataset with a SET statement in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Using-informat-when-reading-from-other-dataset-with-a-SET/m-p/475188#M71129</link>
    <description>&lt;P&gt;??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An informat is for reading raw data in a certain way.&amp;nbsp; Datasets already have formats attached to them, to alter that you change the format of the variable?&lt;/P&gt;
&lt;PRE&gt;data a;
  set test;
  format CC $tform.; 
run;&lt;/PRE&gt;</description>
    <pubDate>Tue, 03 Jul 2018 14:24:34 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-07-03T14:24:34Z</dc:date>
    <item>
      <title>Using informat when reading from other dataset with a SET statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-informat-when-reading-from-other-dataset-with-a-SET/m-p/475180#M71128</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;I know informat is using for reading &lt;STRONG&gt;raw&lt;/STRONG&gt; data. How can I read data from other datasets (normally with a set statement) using a custom informat? I am looking for a permanent modification of the data, not just formatting the values. Also why&amp;nbsp;predefined informats work with the set statement as seen below?&lt;/P&gt;&lt;P&gt;Here is an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input CC $2.;
  datalines;
LU
AT
BE
;run;

proc format ;
  invalue $tform 
    "LU"  = "XX"
    other = "ZZ";
run;

/* 
Output from a:
Expected  Actual
XX        LU
ZZ        AT
ZZ        BE
 */
data a;
  informat CC $tform.; /* custom informat does not work? */
  set test;
run;

/* What about predefined informat?
Output from b:
Expected  Actual
LU        L
AT        A
BE        B
 */
data b;
  informat CC $1.;    /* predefined informat works? */
  set test;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jul 2018 14:05:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-informat-when-reading-from-other-dataset-with-a-SET/m-p/475180#M71128</guid>
      <dc:creator>PavelD</dc:creator>
      <dc:date>2018-07-03T14:05:20Z</dc:date>
    </item>
    <item>
      <title>Re: Using informat when reading from other dataset with a SET statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-informat-when-reading-from-other-dataset-with-a-SET/m-p/475188#M71129</link>
      <description>&lt;P&gt;??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An informat is for reading raw data in a certain way.&amp;nbsp; Datasets already have formats attached to them, to alter that you change the format of the variable?&lt;/P&gt;
&lt;PRE&gt;data a;
  set test;
  format CC $tform.; 
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Jul 2018 14:24:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-informat-when-reading-from-other-dataset-with-a-SET/m-p/475188#M71129</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-07-03T14:24:34Z</dc:date>
    </item>
    <item>
      <title>Re: Using informat when reading from other dataset with a SET statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-informat-when-reading-from-other-dataset-with-a-SET/m-p/475189#M71130</link>
      <description>&lt;P&gt;A couple of things that work ...&amp;nbsp;&amp;nbsp; First run PROC FORMAT.&amp;nbsp; Then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; test&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp; &lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; CC &lt;SPAN class="token punctuation"&gt;$tform&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="token datalines"&gt; &lt;SPAN class="token keyword"&gt;datalines&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;LU &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;AT &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;BE &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token punctuation"&gt;Or:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token punctuation"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; test;&lt;BR /&gt;&amp;nbsp; &lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; CC $&lt;SPAN class="token number"&gt;2&lt;/SPAN&gt;.;&lt;BR /&gt; &lt;SPAN class="token keyword"&gt;datalines&lt;/SPAN&gt;; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token punctuation"&gt;&lt;SPAN class="token data string"&gt;LU &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token punctuation"&gt;&lt;SPAN class="token data string"&gt;AT &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token punctuation"&gt;&lt;SPAN class="token data string"&gt;BE &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token punctuation"&gt;data want;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token punctuation"&gt;set test;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token punctuation"&gt;CC = input(CC, $tform.);&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token punctuation"&gt;run;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jul 2018 14:25:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-informat-when-reading-from-other-dataset-with-a-SET/m-p/475189#M71130</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-07-03T14:25:42Z</dc:date>
    </item>
    <item>
      <title>Re: Using informat when reading from other dataset with a SET statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-informat-when-reading-from-other-dataset-with-a-SET/m-p/475192#M71131</link>
      <description>&lt;P&gt;The informat does not "work" here:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b;
  informat CC $1.;    /* predefined informat works? */
  set test;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;as you rightfully stated, it only works when reading from raw data with an input statement (or in an input function).&lt;/P&gt;
&lt;P&gt;Since here the informat statement sets the attributes before the incoming variables are determined by the set statement, CC is defined with a length of 1, and the values are truncated.&lt;/P&gt;
&lt;P&gt;Now run this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
  informat CC $tform1.;
  set test;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that &lt;EM&gt;both&lt;/EM&gt; data steps cause a WARNING because of the truncation. Maxim 2: read the log!&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jul 2018 14:27:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-informat-when-reading-from-other-dataset-with-a-SET/m-p/475192#M71131</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-03T14:27:24Z</dc:date>
    </item>
    <item>
      <title>Re: Using informat when reading from other dataset with a SET statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-informat-when-reading-from-other-dataset-with-a-SET/m-p/475219#M71133</link>
      <description>&lt;P&gt;Changing the INFORMAT associated with a dataset really does nothing.&amp;nbsp; Perhaps if you opened the dataset in FSEDIT and tried to manually add records it might have an impact.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You state that this "works".&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b;
  informat CC $1.;    /* predefined informat works? */
  set test;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What you have done is forced SAS to define the variable CC as character with a length on one byte.&amp;nbsp; Then when it reads in the existing dataset it truncates the data to fit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Remember that &lt;STRONG&gt;FORMAT&lt;/STRONG&gt; and &lt;STRONG&gt;INFORMAT&lt;/STRONG&gt; are statements are instructions to SAS about what default format or informat to use when translating values to text or the reverse.&amp;nbsp; An INFORMAT or FORMAT statement only has an impact on the &lt;STRONG&gt;definition&lt;/STRONG&gt; of a variable's type and/or length if it is the first place the SAS code references the variable.&amp;nbsp; In general SAS makes a decision about the variable type/length when you first reference the variable.&amp;nbsp; So if the first place you reference it is in a INFORMAT statement then SAS will define the type of the variable to match the informat type.&amp;nbsp; And for character variables it will set the length to match the width of the format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to set the type and/or length of a variable you should use either a &lt;STRONG&gt;LENGTH&lt;/STRONG&gt; or &lt;STRONG&gt;ATTRIB&lt;/STRONG&gt; statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* Truncate CC to one character ;
data b;
  length CC $1;
  set test;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also note that letting SAS guess at how to define a variable can result in lengths that are probably not what you intended.&amp;nbsp; For example if you define a character format that formats one letter codes to longer descriptions and then use a FORMAT statement before defining the variable SAS will set the length to match the length of the display values instead of the actual stored values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
value $testf 'L'='LONG' ;
run;

data test;
  length a $1 ;
  format a b $testf. ;
run;

proc contents data=test;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;The CONTENTS Procedure

Alphabetic List of Variables and Attributes

#    Variable    Type    Len    Format

1    a           Char      1    $TESTF.
2    b           Char      4    $TESTF.
&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Jul 2018 15:08:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-informat-when-reading-from-other-dataset-with-a-SET/m-p/475219#M71133</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-03T15:08:38Z</dc:date>
    </item>
    <item>
      <title>Re: Using informat when reading from other dataset with a SET statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-informat-when-reading-from-other-dataset-with-a-SET/m-p/475308#M71147</link>
      <description>&lt;P&gt;Thank you for clarifying answers and explanations. I am still battling with the basics.&lt;/P&gt;&lt;P&gt;I knew I am using INFORMAT incorrectly, just did not know how exactly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the part I was looking for:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token punctuation"&gt;data want;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token punctuation"&gt;set test;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token punctuation"&gt;CC = input(CC, $tform.);&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token punctuation"&gt;run;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I.e.&amp;nbsp;using put or input function to rewrite existing data. I wrongly thought I could achieve the same thing with informat. I did not want to use format, as it only changes the visual appearance of the data, not the data itself.&lt;/P&gt;&lt;P&gt;Thanks all!&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jul 2018 19:25:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-informat-when-reading-from-other-dataset-with-a-SET/m-p/475308#M71147</guid>
      <dc:creator>PavelD</dc:creator>
      <dc:date>2018-07-03T19:25:17Z</dc:date>
    </item>
    <item>
      <title>Re: Using informat when reading from other dataset with a SET statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-informat-when-reading-from-other-dataset-with-a-SET/m-p/475311#M71150</link>
      <description>&lt;P&gt;An INFORMAT converts text to stored values. You use it with an INPUT statement or an INPUT() function.&lt;/P&gt;
&lt;P&gt;A FORMAT converts stored values to text. You use it with a PUT statement or a PUT() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your case since you are translating character variables you could either use an INFORMAT with an INPUT() function call or a FORMAT with a PUT() function call.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In PROC FORMAT you use a VALUE statement to create a FORMAT and an INVALUE statement to create an INFORMAT.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jul 2018 19:37:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-informat-when-reading-from-other-dataset-with-a-SET/m-p/475311#M71150</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-03T19:37:25Z</dc:date>
    </item>
  </channel>
</rss>

