<?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: error creating a table from a txt file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/error-creating-a-table-from-a-txt-file/m-p/311109#M67146</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Modelling your data step after what PROC IMPORT generates might be useful if you don't know anything about how SAS works, but if you do you can write a much clearer and shorter program yourself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use LENGTH or ATTRIB to define your variables instead of forcing SAS to guess what type of variables they are based on first seeing your variables referenced in an INFORMAT, FORMAT or INPUT statement. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also you don't need to define INFORMATs for normal text strings or numbers. Just add them for things like dates, times, or datetime values that need special treatement. &amp;nbsp;The same applies to FORMATs. &amp;nbsp;There is no value an much danger in permanently attaching $xxx. formats to text strings. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't need to add the $ modifier in your INPUT statement if you have already defined the variable as character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks like the source file you are reading has the literal string 'null' entered when the numeric variable is supposed to mssing. If you are sure that these are the only strange values then perhaps you just need to add ? or ?? modifier to your INPUT statement for that variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  infile cards dlm='|' dsd truncover ;
  length
    ACTIVITY_LOG_ID  8
    ACTIVITY_TYPE_ID  8
    PROBLEM_REASON_ID  8
    SOURCE_DT_TM 8
    AUTHENTICATION_METHOD $500
    ACTIVITY_KEY $50
    ACTIVITY_DETAIL $30000
  ;
  informat SOURCE_DT_TM ANYDTDTM. ;
  format SOURCE_DT_TM datetime20. ;
  input
    ACTIVITY_LOG_ID
    ACTIVITY_TYPE_ID
    PROBLEM_REASON_ID  ?
    SOURCE_DT_TM
    AUTHENTICATION_METHOD
    ACTIVITY_KEY
    ACTIVITY_DETAIL
  ;
cards;
"1257178407"|"683"|"null"|"2016-11-11 12:11:00.0"|method|key|detail
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result for this one example line.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;RULE:      ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----
512        "1257178407"|"683"|"null"|"2016-11-11 12:11:00.0"|method|key|detail
ACTIVITY_LOG_ID=1257178407 ACTIVITY_TYPE_ID=683 PROBLEM_REASON_ID=. SOURCE_DT_TM=11NOV2016:12:11:00
AUTHENTICATION_METHOD=method ACTIVITY_KEY=key ACTIVITY_DETAIL=detail _ERROR_=1 _N_=1
NOTE: The data set WORK.WANT has 1 observations and 7 variables.
NOTE: DATA statement used (Total process time):
      real time           0.59 seconds
      cpu time            0.00 seconds


513  ;
514
515  data _null_; set want;
516   put (_all_) (=/);
517  run;


ACTIVITY_LOG_ID=1257178407
ACTIVITY_TYPE_ID=683
PROBLEM_REASON_ID=.
SOURCE_DT_TM=11NOV2016:12:11:00
AUTHENTICATION_METHOD=method
ACTIVITY_KEY=key
ACTIVITY_DETAIL=detail
NOTE: There were 1 observations read from the data set WORK.WANT.&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 12 Nov 2016 01:50:43 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2016-11-12T01:50:43Z</dc:date>
    <item>
      <title>error creating a table from a txt file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/error-creating-a-table-from-a-txt-file/m-p/311106#M67145</link>
      <description>&lt;P&gt;I'm tring to create a table from a txt file but i think that i don't use the correcto formats or somthing similar because and error appers in one of the columns, i attached the log :&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;NOTE: SAS initialization used:&lt;BR /&gt; real time 0.02 seconds&lt;BR /&gt; cpu time 0.02 seconds&lt;BR /&gt; &lt;BR /&gt;1 options&lt;BR /&gt;2 metaserver=srvsaspvlsu101.us.santanderus.corp&lt;BR /&gt;3 metaport=8561&lt;BR /&gt;4 metauser="prhtsasd"&lt;BR /&gt;5 metapass=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&lt;BR /&gt;6 metarepository=Foundation;&lt;BR /&gt;7 &lt;BR /&gt;8 libname Techlogs "/interfacesas/fraud/techlogs";&lt;BR /&gt;NOTE: Libref TECHLOGS was successfully assigned as follows: &lt;BR /&gt; Engine: V9 &lt;BR /&gt; Physical Name: /interfacesas/fraud/techlogs&lt;BR /&gt;9 &lt;BR /&gt;10 proc import datafile="/interfacesas/fraud/techlogs/ch_activity_log.txt" out=Techlogs.ch_activity_log dbms=DLM replace;&lt;BR /&gt;11 DELIMITER='|';&lt;BR /&gt;12 getnames=no;&lt;BR /&gt;13 run;&lt;/P&gt;
&lt;P&gt;14 /**********************************************************************&lt;BR /&gt;15 * PRODUCT: SAS&lt;BR /&gt;16 * VERSION: 9.2&lt;BR /&gt;17 * CREATOR: External File Interface&lt;BR /&gt;18 * DATE: 11NOV16&lt;BR /&gt;19 * DESC: Generated SAS Datastep Code&lt;BR /&gt;20 * TEMPLATE SOURCE: (None Specified.)&lt;BR /&gt;21 ***********************************************************************/&lt;BR /&gt;22 data TECHLOGS.CH_ACTIVITY_LOG ;&lt;BR /&gt;23 %let _EFIERR_ = 0; /* set the ERROR detection macro variable */&lt;BR /&gt;24 infile '/interfacesas/fraud/techlogs/ch_activity_log.txt' delimiter = '|' MISSOVER DSD lrecl=32767 ;&lt;BR /&gt;25 informat VAR1 $12. ;&lt;BR /&gt;^L2 The SAS System 18:12 Friday, November 11, 2016&lt;/P&gt;
&lt;P&gt;26 informat VAR2 $8. ;&lt;BR /&gt;27 informat VAR3 $6. ;&lt;BR /&gt;28 informat VAR4 $23. ;&lt;BR /&gt;29 informat VAR5 $12. ;&lt;BR /&gt;30 informat VAR6 $15. ;&lt;BR /&gt;31 informat VAR7 $465. ;&lt;BR /&gt;32 format VAR1 $12. ;&lt;BR /&gt;33 format VAR2 $8. ;&lt;BR /&gt;34 format VAR3 $6. ;&lt;BR /&gt;35 format VAR4 $23. ;&lt;BR /&gt;36 format VAR5 $12. ;&lt;BR /&gt;37 format VAR6 $15. ;&lt;BR /&gt;38 format VAR7 $465. ;&lt;BR /&gt;39 input&lt;BR /&gt;40 VAR1 $&lt;BR /&gt;41 VAR2 $&lt;BR /&gt;42 VAR3 $&lt;BR /&gt;43 VAR4 $&lt;BR /&gt;44 VAR5 $&lt;BR /&gt;45 VAR6 $&lt;BR /&gt;46 VAR7 $&lt;BR /&gt;47 ;&lt;BR /&gt;48 if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable */&lt;BR /&gt;49 run;&lt;/P&gt;
&lt;P&gt;NOTE: The infile '/interfacesas/fraud/techlogs/ch_activity_log.txt' is:&lt;BR /&gt; Filename=/interfacesas/fraud/techlogs/ch_activity_log.txt,&lt;BR /&gt; Owner Name=prhtsas,Group Name=sas,&lt;BR /&gt; Access Permission=rw-rw-r--,&lt;BR /&gt; Last Modified=Fri Nov 11 17:21:15 2016,&lt;BR /&gt; File Size (bytes)=6103862&lt;/P&gt;
&lt;P&gt;NOTE: 30620 records were read from the infile '/interfacesas/fraud/techlogs/ch_activity_log.txt'.&lt;BR /&gt; The minimum record length was 70.&lt;BR /&gt; The maximum record length was 958.&lt;BR /&gt;NOTE: The data set TECHLOGS.CH_ACTIVITY_LOG has 30620 observations and 7 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt; real time 0.09 seconds&lt;BR /&gt; cpu time 0.08 seconds&lt;/P&gt;
&lt;P&gt;30620 rows created in TECHLOGS.CH_ACTIVITY_LOG from /interfacesas/fraud/techlogs/ch_activity_log.txt.&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt;NOTE: TECHLOGS.CH_ACTIVITY_LOG data set was successfully created.&lt;BR /&gt;NOTE: PROCEDURE IMPORT used (Total process time):&lt;BR /&gt; real time 12.47 seconds&lt;BR /&gt; cpu time 0.50 seconds&lt;/P&gt;
&lt;P&gt;50 &lt;BR /&gt;51 data Techlogs.ch_activity_log;&lt;BR /&gt;52 infile '/interfacesas/fraud/techlogs/ch_activity_log.txt' delimiter = '|' TRUNCOVER DSD lrecl=32767 ;&lt;BR /&gt;53 informat ACTIVITY_LOG_ID 12. ;&lt;BR /&gt;54 informat ACTIVITY_TYPE_ID 8. ;&lt;BR /&gt;55 informat PROBLEM_REASON_ID 8. ;&lt;BR /&gt;56 informat SOURCE_DT_TM yymmdd10. ;&lt;BR /&gt;^L3 The SAS System 18:12 Friday, November 11, 2016&lt;/P&gt;
&lt;P&gt;57 informat AUTHENTICATION_METHOD $500. ;&lt;BR /&gt;58 informat ACTIVITY_KEY $50. ;&lt;BR /&gt;59 informat ACTIVITY_DETAIL $30000. ;&lt;BR /&gt;60 format ACTIVITY_LOG_ID 12. ;&lt;BR /&gt;61 format ACTIVITY_TYPE_ID 8. ;&lt;BR /&gt;62 format PROBLEM_REASON_ID 8. ;&lt;BR /&gt;63 format SOURCE_DT_TM yymmdd10. ;&lt;BR /&gt;64 format AUTHENTICATION_METHOD $500. ;&lt;BR /&gt;65 format ACTIVITY_KEY $50. ;&lt;BR /&gt;66 format ACTIVITY_DETAIL $30000. ;&lt;BR /&gt;67 &lt;BR /&gt;68 input&lt;BR /&gt;69 ACTIVITY_LOG_ID&lt;BR /&gt;70 ACTIVITY_TYPE_ID&lt;BR /&gt;71 PROBLEM_REASON_ID&lt;BR /&gt;72 SOURCE_DT_TM&lt;BR /&gt;73 AUTHENTICATION_METHOD $&lt;BR /&gt;74 ACTIVITY_KEY $&lt;BR /&gt;75 ACTIVITY_DETAIL $&lt;BR /&gt;76 &lt;BR /&gt;77 ;&lt;BR /&gt;78 run;&lt;/P&gt;
&lt;P&gt;NOTE: The infile '/interfacesas/fraud/techlogs/ch_activity_log.txt' is:&lt;BR /&gt; Filename=/interfacesas/fraud/techlogs/ch_activity_log.txt,&lt;BR /&gt; Owner Name=prhtsas,Group Name=sas,&lt;BR /&gt; Access Permission=rw-rw-r--,&lt;BR /&gt; Last Modified=Fri Nov 11 17:21:15 2016,&lt;BR /&gt; File Size (bytes)=6103862&lt;/P&gt;
&lt;P&gt;NOTE: Invalid data for PROBLEM_REASON_ID in line 1 20-23.&lt;BR /&gt;RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0 &lt;BR /&gt;1 "1257178407"|"683"|"null"|"2016-11-11 12:11:00.0"|"RETAIL OLB"|"1478884290064"|"User ID: I1677978; T&lt;BR /&gt; 101 imestamp: 2016-11-11 12:11:30.036; Account From: A8 2313726919996325679; Account To: A8 231372691559&lt;BR /&gt; 201 1083366; Date: 11/11/2016; Amount: $1,200.00; Customer Name: FABRICE TAFO; IP Address: 71.235.200.15&lt;BR /&gt; 301 1; Device information: 99000449989937|SM-G900P; Geo-location information: sheryl||#0#||; " 390&lt;BR /&gt;ACTIVITY_LOG_ID=1257178407 ACTIVITY_TYPE_ID=683 PROBLEM_REASON_ID=. SOURCE_DT_TM=2016-11-11 AUTHENTICATION_METHOD=RETAIL OLB&lt;BR /&gt;ACTIVITY_KEY=1478884290064&lt;BR /&gt;ACTIVITY_DETAIL=User ID: I1677978; Timestamp: 2016-11-11 12:11:30.036; Account From: A8 2313726919996325679; Account To: A8 23137269&lt;BR /&gt;15591083366; Date: 11/11/2016; Amount: $1,200.00; Customer Name: FABRICE TAFO; IP Address: 71.235.200.151; Device information: 99000&lt;BR /&gt;449989937|SM-G900P; Geo-location information: sheryl||#0#||; _ERROR_=1 _N_=1&lt;BR /&gt;NOTE: Invalid data for PROBLEM_REASON_ID in line 2 22-25.&lt;BR /&gt;2 "1257178415"|"13244"|"null"|"2016-11-11 12:11:00.0"|"IVR"|"00000"|"Customer ID: #582579469#||IOC Acc&lt;BR /&gt; 101 ount Type: Telephone Banking" 129&lt;BR /&gt;ACTIVITY_LOG_ID=1257178415 ACTIVITY_TYPE_ID=13244 PROBLEM_REASON_ID=. SOURCE_DT_TM=2016-11-11 AUTHENTICATION_METHOD=IVR&lt;BR /&gt;ACTIVITY_KEY=00000 ACTIVITY_DETAIL=Customer ID: #582579469#||IOC Account Type: Telephone Banking _ERROR_=1 _N_=2&lt;BR /&gt;NOTE: Invalid data for PROBLEM_REASON_ID in line 3 22-25.&lt;BR /&gt;3 "1257178417"|"13290"|"null"|"2016-11-11 12:11:00.0"|"IVR"|"00000"|"Customer ID: #193623035#||Account&lt;BR /&gt; 101 Number: #2313726918191022877#" 131&lt;BR /&gt;ACTIVITY_LOG_ID=1257178417 ACTIVITY_TYPE_ID=13290 PROBLEM_REASON_ID=. SOURCE_DT_TM=2016-11-11 AUTHENTICATION_METHOD=IVR&lt;BR /&gt;ACTIVITY_KEY=00000 ACTIVITY_DETAIL=Customer ID: #193623035#||Account Number: #2313726918191022877# _ERROR_=1 _N_=3&lt;BR /&gt;NOTE: Invalid data for PROBLEM_REASON_ID in line 4 22-25.&lt;BR /&gt;4 "1257178419"|"14013"|"null"|"2016-11-11 12:11:00.0"|"RETAIL OLB"|"1478884291048"|"User: aDAccWZG; Ti&lt;BR /&gt; 101 mestamp: 2016-11-11 12:11:30.983; Account From: A8 2313726910095172103; Account To: A8 2313726913671&lt;BR /&gt; 201 330155; Date: 11/14/2016; Amount: $500.00; Customer Name: MAXINE A MARTIN; IP Address: 73.100.98.186&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;----------------------------------------------------------------------------------------------------------------------------------------------------------------&lt;/P&gt;</description>
      <pubDate>Fri, 11 Nov 2016 23:56:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/error-creating-a-table-from-a-txt-file/m-p/311106#M67145</guid>
      <dc:creator>kaoru013</dc:creator>
      <dc:date>2016-11-11T23:56:47Z</dc:date>
    </item>
    <item>
      <title>Re: error creating a table from a txt file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/error-creating-a-table-from-a-txt-file/m-p/311109#M67146</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Modelling your data step after what PROC IMPORT generates might be useful if you don't know anything about how SAS works, but if you do you can write a much clearer and shorter program yourself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use LENGTH or ATTRIB to define your variables instead of forcing SAS to guess what type of variables they are based on first seeing your variables referenced in an INFORMAT, FORMAT or INPUT statement. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also you don't need to define INFORMATs for normal text strings or numbers. Just add them for things like dates, times, or datetime values that need special treatement. &amp;nbsp;The same applies to FORMATs. &amp;nbsp;There is no value an much danger in permanently attaching $xxx. formats to text strings. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't need to add the $ modifier in your INPUT statement if you have already defined the variable as character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks like the source file you are reading has the literal string 'null' entered when the numeric variable is supposed to mssing. If you are sure that these are the only strange values then perhaps you just need to add ? or ?? modifier to your INPUT statement for that variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  infile cards dlm='|' dsd truncover ;
  length
    ACTIVITY_LOG_ID  8
    ACTIVITY_TYPE_ID  8
    PROBLEM_REASON_ID  8
    SOURCE_DT_TM 8
    AUTHENTICATION_METHOD $500
    ACTIVITY_KEY $50
    ACTIVITY_DETAIL $30000
  ;
  informat SOURCE_DT_TM ANYDTDTM. ;
  format SOURCE_DT_TM datetime20. ;
  input
    ACTIVITY_LOG_ID
    ACTIVITY_TYPE_ID
    PROBLEM_REASON_ID  ?
    SOURCE_DT_TM
    AUTHENTICATION_METHOD
    ACTIVITY_KEY
    ACTIVITY_DETAIL
  ;
cards;
"1257178407"|"683"|"null"|"2016-11-11 12:11:00.0"|method|key|detail
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result for this one example line.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;RULE:      ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----
512        "1257178407"|"683"|"null"|"2016-11-11 12:11:00.0"|method|key|detail
ACTIVITY_LOG_ID=1257178407 ACTIVITY_TYPE_ID=683 PROBLEM_REASON_ID=. SOURCE_DT_TM=11NOV2016:12:11:00
AUTHENTICATION_METHOD=method ACTIVITY_KEY=key ACTIVITY_DETAIL=detail _ERROR_=1 _N_=1
NOTE: The data set WORK.WANT has 1 observations and 7 variables.
NOTE: DATA statement used (Total process time):
      real time           0.59 seconds
      cpu time            0.00 seconds


513  ;
514
515  data _null_; set want;
516   put (_all_) (=/);
517  run;


ACTIVITY_LOG_ID=1257178407
ACTIVITY_TYPE_ID=683
PROBLEM_REASON_ID=.
SOURCE_DT_TM=11NOV2016:12:11:00
AUTHENTICATION_METHOD=method
ACTIVITY_KEY=key
ACTIVITY_DETAIL=detail
NOTE: There were 1 observations read from the data set WORK.WANT.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 12 Nov 2016 01:50:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/error-creating-a-table-from-a-txt-file/m-p/311109#M67146</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-11-12T01:50:43Z</dc:date>
    </item>
  </channel>
</rss>

