Importing .csv files and saving as .dta - csv

I have a folder containing a number of csv files, e.g. "leeds dz.csv", "leeds gh.csv", "leeds fr.csv". The first part of the file names is constant (i.e. always "leeds").
I want to import each to Stata individually, convert to .dta file and save it. Currently I have this code:
cd "etcetc"
clear
local myfilelist : dir . files"*.csv"
foreach file of local myfilelist {
drop _all
insheet using `file', comma
local outfile = subinstr("`file'",".csv","",.)
save "`outfile'", replace
}
The code works fine if I rename all the .csv files manually to delete the "leeds" part, ie if each .csv is named "dz.csv" instead of "leeds dz.csv" etc.
However, if I do not do this deletion I receive the error "invalid 'dz.csv' "
I'm guessing this has something to do with my 3rd line of code, in particular the "*.csv". But I'm unsure how to adapt the code/ why it won't allow me to import files with a space in the name?

The line
insheet using `file', comma
will be problematic with any filename containing spaces.
Try
insheet using "`file'", comma
The help for insheet is quite explicit on this:
If filename is specified without an extension, .raw is assumed. If your
filename contains embedded spaces, remember to enclose it in double
quotes.

Related

My schema.ini file is being ignored when using DoCmd.TransferText() from .Net

My schema.ini file is being ignored.I get the same results whether I have a scheme.ini file in the same folder as my tab file or not. All of the columns end up in a single column. I am trying to use a schema.ini as I am importing tab delimited files. The results make perfect sense if it is trying to import a comma delim file.
So my postulate is that the schema.ini file is just being ignored.
I am running Access from a .Net program using Microsoft Access 14.0 Object.Library.
I am using this command from .net:
Access.DoCmd.TransferText( Microsoft.Office.Interop.Access.AcTextTransferType.acImportDelim, , TableName, TabFile, HasFieldNames)
Here is my schema.ini file, not that it matters since it is being completely ignored:
[impacts.txt]
Format=TabDelimited
ColNameHeader=True
MaxScanRows=0
Clues? Thanks!
EDIT:
I tried running this from within an Access Module with the same results.
I tried editing the registry to change the Format value there. Same results.
Consider an action query, either append or make-table, as the use of schema.ini files can work directly in an Access query of a text file. Below assumes .ini file is in same directory as text file.
INSERT INTO mytableName
SELECT * FROM [text;Database=C:\Path\To\Text\File].[impacts.txt]
SELECT * INTO newtableName FROM [text;Database=C:\Path\To\Text\File].[impacts.txt]

problems in copying a csv file from s3 to redshift

i am getting the following error if i run a copy command to copy contents of a .csv file in s3 to a table in redshift.
error:"String length exceeds DDL length".
i am using following copy command:
COPY enjoy from 's3://nmk-redshift-bucket/my_workbook.csv' CREDENTIALS 'aws_access_key_id=”****”;aws_secret_access_key=’**** ' CSV QUOTE '"' DELIMITER ',' NULL AS '\0'
i figured lets open the link given by s3 for my file through was console.
link for the work book is :
link to my s3bucket cvs file
the above file is filled with many weird characters i really don't understand.
the copy command is taking these characters instead of the information i have entered in my csv file.So hence leading to string length exceeded error.
i use sql workbench to query.My 'stl_load_errors' table in redshift has raw_field_values component similar to the chars in the link i mentioned above, thats how i got to know how its taking in the input
i am new to aws and utf-8 configs. so please i appreciate help on this
The link you provide points to a .xlsx file (but has a .csv extension instead of .xlsx), which is actually a zip file.
That is why you see those strange characters, the first 2 being 'PK', which means it is a zip file.
So you will have to export to .csv first, before using the file.

cannot load simple csv file into tableau public 9.3

I am trying to load the following simple csv file into tableau public 9.3:
customers,item1,item2,item3,item4
1,0,0,0,0
2,0,0,0,0
3,0,0,0,0
However, it doesn't read the file as separate columns, despite the field separator being Comma. Instead it treats the whole line as one column. Any help would be greatly appreciated :
If you change your locale settings to English US you will be able to load the file. You should also be able to work around this by creating a schema.ini file.
Go to Data > Manage fields > [Field] Options
You can also control imported CSV behavior post import both by splitting individual columns (which will remain split on update as well), or by the image below at the CSV level.
That doesn`t work for me. So I reopen the .csv file in Excel and save it again in .csv format with ',' as the delimeter.
After that my file looks like .csv with ';' delimeter and works with Tableau.

Importing PIPE delimited format txt into MySQL via PHPMyAdmin

I am importing some thousands lines of Data from a .txt file containing two columns and the format is as it follows:
A8041550408#=86^:|blablablablablablablablablablablablablablablablablablablabla1
blablablablablablablablablablablablablablablablablablablabla2
blablablablablablablablablablablablablablablablablablablabla3
A8041550408#=86^:|blablablablablablablablablablablablablablablablablablablabla1
blablablablablablablablablablablablablablablablablablablabla2
A8041550408#=86^:|blablablablablablablablablablablablablablablablablablablabla1
blablablablablablablablablablablablablablablablablablablabla2
blablablablablablablablablablablablablablablablablablablabla3
blablablablablablablablablablablablablablablablablablablabla4
etc....
What I have done so far is create a table with the two fields, but when i try to import the .txt file as a CSV and putting / Columns separated By : | /, I get an error:
"Invalid column count in CSV input on line 2."
Which is quite obvious since the second line of the .txt file is empty.
Moreover, I have tried importing the file as a CSV using LOAD DATA, and it didn't work as well it has just filled up the table with random words and phrases from the .txt file .
So my question is : How can I import the data from this file ?
You have to fix your file; in its current state you cannot expect the import module to be able to understand it. First step would be to remove the empty lines: How to remove blank lines from a Unix file

View semicolon-separated .csv files in gnumeric

I have a semicolon-separated csv file over here, and I would like to be able to look at it with gnumeric. Sadly, gnumeric does not read the semicolon as a separator.
I have tried:
appending sep=; on the first line
clicking through the GUI menus
using sed to replace the semicolons with commas (sadly, that leads to breakage, since by document occasionally uses commas within cells
What else can I do?
In recent versions of gnumeric a new Import Data tool is available. To launch the tool choose Data|Import Data|Import Text File... from the menu.
In the Import Data File dialog choose your file and hit Open.
In the next screen select Separated format and click Forward
In the following screen select a separator from a number of available options and click Forward once again to choose the columns to import.
Click Finish to complete.
Solution that worked for me in a comma separated csv file with dot decimal separators:
Open .csv file from a text editor
replace all "," with ";" (semicolon)
replace all dot decimal separators "." with ","
save file
open gnumeric, go to Data -> Get External Data -> Import Text File
and then open the saved file
hit Forward and Finish
save as a gnumeric file