<?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: How do I apply an informat for variable record length in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-an-informat-for-variable-record-length/m-p/259327#M50161</link>
    <description>Hi reeza, thank you for the answer.</description>
    <pubDate>Mon, 28 Mar 2016 11:42:19 GMT</pubDate>
    <dc:creator>vamshi1</dc:creator>
    <dc:date>2016-03-28T11:42:19Z</dc:date>
    <item>
      <title>How do I apply an informat for variable record length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-an-informat-for-variable-record-length/m-p/259018#M50032</link>
      <description>&lt;P&gt;Hi Guyz, I'm new to SAS programming. I'm writing an instream program in sas studio 9.4. The ename variable consists of variable length characters. I don't know which informat to use. When I'm running the program, SAS is throwing me an error message. Please someone help me out in writing the program in a correct way.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
input Empid Ename $char16. Salary 6. Loc $char10. ; 
datalines; 
101 Vamshi Gulaigiri 60000 Hyderabad 
102 Aditya Vanipenta 70000 Bangalore 
103 Keerthi Perala 35000 Hyderabad 
104 Kesav Murari 80000 Newyork 
105 Gopala Krishna 50000 Hyderabad 
; 
run; 
proc print data = temp; 
run;

Error Message [log]: 1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 55 56 data temp; 57 infile datalines; 58 input Empid Ename $char16. Salary 6. Loc $char10. ; 59 datalines; NOTE: Invalid data for Salary in line 62 22-27. RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0 62 103 Keerthi Perala 35000 Hyderabad Empid=103 Ename=Keerthi Perala 3 Salary=. Loc=yderabad _ERROR_=1 _N_=3 NOTE: The data set WORK.TEMP has 5 observations and 4 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds user cpu time 0.01 seconds system cpu time 0.00 seconds memory 784.15k OS Memory 28580.00k Timestamp 03/21/2016 03:14:34 PM Step Count 70 Switch Count 50 Page Faults 0 Page Reclaims 377 Page Swaps 0 Voluntary Context Switches 146 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 264 63 ; 64 run; 65 proc print data = temp; 66 67 run; NOTE: There were 5 observations read from the data set WORK.TEMP. NOTE: PROCEDURE PRINT used (Total process time): real time 0.02 seconds user cpu time 0.03 seconds system cpu time 0.00 seconds memory 1649.87k OS Memory 28836.00k Timestamp 03/21/2016 03:14:34 PM Step Count 71 Switch Count 28 Page Faults 0 Page Reclaims 155 Page Swaps 0 Voluntary Context Switches 57 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 8 68 69 70 71 72 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 84&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Mar 2016 18:09:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-an-informat-for-variable-record-length/m-p/259018#M50032</guid>
      <dc:creator>vamshi1</dc:creator>
      <dc:date>2016-03-25T18:09:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do I apply an informat for variable record length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-an-informat-for-variable-record-length/m-p/259027#M50036</link>
      <description>&lt;P&gt;First, some hints:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To post SAS code, use the "little running man" icon; this displays the code in your post with a fixed width font and typical SAS syntax highlighting.&lt;/P&gt;
&lt;P&gt;To post log excerpts and the like, use the "{i}" icon, which also uses a fixed width font, but without syntax highlighting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regarding your problem:&lt;/P&gt;
&lt;P&gt;Your "ename" column contains values with a delimiter inside. This makes it very hard to handle, if not impossible, with a simple input.&lt;/P&gt;
&lt;P&gt;If you have access to the data source, try to wrap the column in quotes and use the DSD option in the infile statetement in SAS.&lt;/P&gt;
&lt;P&gt;If you cannot manipulate the data source, options are:&lt;/P&gt;
&lt;P&gt;- if ename always consists of the same number of words, read those separately and concatenate&lt;/P&gt;
&lt;P&gt;- read the whole line into one variable, count the number of words, and then dynamically split the whole string into fields&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ie&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
length
  empid 8
  ename $30
  salary 8
  loc $10
  whole_line $ 100
;
input;
whole_line = _infile_;
x = countw(whole_line);
do i = 2 to x - 2;
  ename = catx(' ',trim(ename),trim(scan(whole_line,i)));
end;
empid = input(scan(whole_line,1),3.);
salary = input(scan(whole_line,x -1),best.);
loc = scan(whole_line,x);
drop whole_line x i;
cards;
101 Vamshi Gulaigiri 60000 Hyderabad
102 Aditya Vanipenta 70000 Bangalore
103 Keerthi Perala 35000 Hyderabad
104 Kesav Murari 80000 Newyork
105 Gopala Krishna 50000 Hyderabad
;
run;

proc print data = temp;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2016 08:55:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-an-informat-for-variable-record-length/m-p/259027#M50036</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-03-25T08:55:38Z</dc:date>
    </item>
    <item>
      <title>Re: How do I apply an informat for variable record length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-an-informat-for-variable-record-length/m-p/259028#M50037</link>
      <description>&lt;P&gt;Try using an informat statement instead of placing informants in your input statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please post out your code within a code block, see the {I} or little paper notebook icon at the top of the editor. Your code/errors are not readable in their current format.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2016 08:56:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-an-informat-for-variable-record-length/m-p/259028#M50037</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-25T08:56:36Z</dc:date>
    </item>
    <item>
      <title>Re: How do I apply an informat for variable record length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-an-informat-for-variable-record-length/m-p/259098#M50061</link>
      <description>&lt;P&gt;I think all you need is to change&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input Empid Ename $char16. Salary 6. Loc $char10. ; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input Empid Ename &amp;amp;$16. Salary :6. Loc :$10. ; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You are trying to use formatted when you need list input. &amp;nbsp;Missing values in the data will need to be entered as a period and you need two spaces between ENAME and SALARY to read a character field with embedded&amp;nbsp;space.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;62 103 Keerthi Perala 35000 Hyderabad&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Mar 2016 17:18:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-an-informat-for-variable-record-length/m-p/259098#M50061</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-03-25T17:18:58Z</dc:date>
    </item>
    <item>
      <title>Re: How do I apply an informat for variable record length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-an-informat-for-variable-record-length/m-p/259105#M50063</link>
      <description>&lt;P&gt;I've edited your post above to make it more clear.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would use a different solution - assuming that the name is always in two parts, read it in as first and last name, so two separate variables. Then I use the concatenate function to create the name, to combine the first and last name into one variable.&lt;/P&gt;
&lt;P&gt;I also create a specific informat statement to read the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
informat empid 8. first_name $20. last_name $20. Salary 8. loc $10.;
input Empid first_name last_name Salary Loc; 
datalines; 
101 Vamshi Gulaigiri 60000 Hyderabad 
102 Aditya Vanipenta 70000 Bangalore 
103 Keerthi Perala 35000 Hyderabad 
104 Kesav Murari 80000 Newyork 
105 Gopala Krishna 50000 Hyderabad 
; 
run; 
proc print data = temp; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2016 18:13:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-an-informat-for-variable-record-length/m-p/259105#M50063</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-25T18:13:21Z</dc:date>
    </item>
    <item>
      <title>Re: How do I apply an informat for variable record length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-an-informat-for-variable-record-length/m-p/259325#M50159</link>
      <description>&lt;P&gt;Thank you kurt for your answer. Actually it worked.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Mar 2016 11:38:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-an-informat-for-variable-record-length/m-p/259325#M50159</guid>
      <dc:creator>vamshi1</dc:creator>
      <dc:date>2016-03-28T11:38:52Z</dc:date>
    </item>
    <item>
      <title>Re: How do I apply an informat for variable record length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-an-informat-for-variable-record-length/m-p/259326#M50160</link>
      <description>&lt;P&gt;Thank you for the answer. It worked and I understood the concept.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Mar 2016 11:40:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-an-informat-for-variable-record-length/m-p/259326#M50160</guid>
      <dc:creator>vamshi1</dc:creator>
      <dc:date>2016-03-28T11:40:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do I apply an informat for variable record length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-an-informat-for-variable-record-length/m-p/259327#M50161</link>
      <description>Hi reeza, thank you for the answer.</description>
      <pubDate>Mon, 28 Mar 2016 11:42:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-an-informat-for-variable-record-length/m-p/259327#M50161</guid>
      <dc:creator>vamshi1</dc:creator>
      <dc:date>2016-03-28T11:42:19Z</dc:date>
    </item>
  </channel>
</rss>

