{"id":1262,"date":"2016-01-23T08:11:52","date_gmt":"2016-01-23T13:11:52","guid":{"rendered":"http:\/\/www.amibroker.com\/kb\/?p=1262"},"modified":"2016-01-28T08:16:29","modified_gmt":"2016-01-28T13:16:29","slug":"how-to-create-custom-import-definition-for-ascii-importer","status":"publish","type":"post","link":"https:\/\/www.amibroker.com\/wordpress\/kb\/2016\/01\/23\/how-to-create-custom-import-definition-for-ascii-importer\/","title":{"rendered":"How to create custom import definition for ASCII importer"},"content":{"rendered":"

When we use File->Import ASCII<\/strong> to import data, we can choose import file format using one pre-defined import format definitions. As it is explained in the manual (http:\/\/www.amibroker.com\/guide\/d_ascii.html<\/a>) it is also possible to create our custom import definitions to match data we are trying to import. This article explains all the required steps.<\/p>

The easiest method to create import definition is to use File->Import Wizard<\/strong>. In the first page, select at least one file in the format we want to import and on the second page configure columns:<\/p>

\"Import<\/p>

This all easy when we are importing quotation data, but when we are importing non-quotation data such as category assignments, we can not select appropriate columns using Import Wizard. In such case we need to type-in appropriate $FORMAT command in the “Additional commands” field of Import Wizard. <\/p>

For example if we have file with categories like this:<\/p>

\"DDD\",\"3D Systems Corporation\",\"Technology\",\"Computer Software: Prepackaged Software\",1\r\"MMM\",\"3M Company\",\"Health Care\",\"Medical\/Dental Instruments\",1\r\"WBAI\",\"500.com Limited\",\"Consumer Services\",\"Services-Misc. Amusement & Recreation\",1\r\"WUBA\",\"58.com Inc.\",\"Technology\",\"Computer Software: Programming, Data Processing\",1\r\"AHC\",\"A.H. Belo Corporation\",\"Consumer Services\",\"Newspapers\/Magazines\",1\r\"ATEN\",\"A10 Networks, Inc.\",\"Technology\",\"Computer Communications Equipment\",1\r\"AIR\",\"AAR Corp.\",\"Capital Goods\",\"Aerospace\",1\r\"AAN\",\"Aaron's,  Inc.\",\"Technology\",\"Diversified Commercial Services\",1<\/pre>

We need to add the following commands in the “Additional commands” field of Import Wizard<\/p>

$FORMAT Ticker,FullName,SectorName,IndustryName,Group\r$OVERWRITE 1\r$CLEANSECTORS 1\r$SORTSECTORS 1<\/pre>

First line tells AmiBroker the column meaning, second line tells it to overwrite existing data. Last two lines tell AmiBroker to wipe existing category structure and sort imported sectors alphabetically. Be sure NOT to specify $CLEANSECTORS command when you do NOT want to wipe existing category structure.<\/p>

We also need to mark “No quotation data” box in the second page of Import wizard to tell AmiBroker that the file that we are importing does not contain quotes and it should switch off all price checking.<\/p>

\"Import<\/p>

Finally, in the last step of the wizard save the format definition:<\/p>

\"Import<\/p>

Once we do this, next time we use File->Import ASCII<\/strong> a new selection My own format<\/strong> will appear in the Files of type<\/strong> combo box in the file selector dialog.<\/p>

\"Import<\/p>

It is worth noting that import definitions are plain text files that are stored in “Formats” subfolder of AmiBroker directory, and the list of available import definitions that appears in “Files of type” combo box, is also a plain text file called “import.types” that is located in the same subfolder. So, advanced users may also modify those files directly using plain text editor such as Notepad. It is all explained in great detail in the manual http:\/\/www.amibroker.com\/guide\/d_ascii.html<\/a><\/p>","protected":false},"excerpt":{"rendered":"

When we use File->Import ASCII to import data, we can choose import file format using one pre-defined import format definitions. As it is explained in the manual (http:\/\/www.amibroker.com\/guide\/d_ascii.html) it is also possible to create our custom import definitions to match data we are trying to import. This article explains all the required steps.The easiest method […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[54,47],"_links":{"self":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/1262"}],"collection":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/comments?post=1262"}],"version-history":[{"count":2,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/1262\/revisions"}],"predecessor-version":[{"id":1276,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/1262\/revisions\/1276"}],"wp:attachment":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/media?parent=1262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/categories?post=1262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/tags?post=1262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}