- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi, everyone. I just started using SAS. I don't know how to import a text file.
Here an example of my text file:
code;description;total
1;hi;201
2;hey;301
3;good;401
That's it. BTW I don't know the field length just that it's semicolon delimited.
I just tried this but it doesn't work:
data Nombre_cuentas_cualit_1001
infile "C:\proyecto_sas_bv\Nombre_cuentas_cualit_1001.txt" dlm=';';
input code--total;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Use PROC IMPORT. Check the log to see the code generated.
Or if you want to write a data step, look up the INFILE statement and see what options are available. FIRSTOBS tells SAS which line the data starts at.
You do need to explicilty list all your variables when you use this method though, your INPUT statement isn't valid here. If you listed all variables in a FORMAT or LENGTH statement ahead of time, that would work but you haven't in this case.
https://stats.idre.ucla.edu/sas/faq/how-do-i-read-in-a-delimited-ascii-file-in-sas/
@eduarxj32 wrote:
Hi, everyone. I just started using SAS. I don't know how to import a text file.
Here an example of my text file:
code;description;total
1;hi;201
2;hey;301
3;good;401
That's it. BTW I don't know the field length just that it's semicolon delimited.
I just tried this but it doesn't work:
data Nombre_cuentas_cualit_1001
infile "C:\proyecto_sas_bv\Nombre_cuentas_cualit_1001.txt" dlm=';';
input code--total;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your answer. I just found this example in SAS documentation:
proc import datafile="C:\proyecto_sas_bv\Nombre_cuentas_cualit_1001.txt"
out=Nombre_cuentas_cualit_1001
dbms=dlm
replace;
dlm=';';
run;
But I can not see the error it says:
ERROR 180-322: Statement is not valid or it is used out of proper order.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Don't waste time with PROC IMPORT when reading text files, in the end you are faster writing the code yourself:
data want;
infile datalines dlm=";" dsd truncover firstobs=2;
input code :$1. description :$10. total;
datalines4;
code;description;total
1;hi;201
2;hey;301
3;good;401
;;;;
For your actual file, replace the DATALINES keyword in the INFILE statement with your filename, and remove the DATALINES4; block.