Hi, i'm trying to import a txt file delimited by ";" into SAS, but when i use the following code:
DATA TEST;
LENGTH
P_TERM $ 6
amount 8
Moeda_1 $ 3 ;
FORMAT
P_TERM $CHAR6.
amount COMMA12.2
Moeda_1 $CHAR3. ;
INFORMAT
P_TERM $CHAR6.
amount COMMA12.2
Moeda_1 $CHAR3. ;
INFILE "/home/FILE.txt"
DLM=";"
FIRSTOBS=2
MISSOVER
DSD ;
INPUT
P_TERM $CHAR6.
amount COMMA12.2
Moeda_1 $CHAR3. ;
RUN;
The result its not right as follows:
But when i use the import wizard formating it the same way it works and i get this:
I need to import by code, because i will use File*.txt to get all files in a directory and there are moren than 3 columns, but only these get this trouble.
Tks,
Rodrigo Elias
Try
INPUT
P_TERM :$6.
amount :COMMA12.
Moeda_1 :$3. ;
PG
I tested, not works.
Tks
Try this:
DATA TEST;
LENGTH
P_TERM $ 6
amount 8
Moeda_1 $ 3 ;
FORMAT
P_TERM $CHAR6.
amount COMMA12.2
Moeda_1 $CHAR3. ;
INFORMAT
P_TERM $CHAR6.
amount COMMA12.2
Moeda_1 $CHAR3. ;
INFILE "/home/FILE.txt"
DLM=";"
FIRSTOBS=2
TRUNCOVER
DSD ;
INPUT
P_TERM $
amount
Moeda_1 $;
RUN;
Not working.
Attach sample data.
Try TRUNCOVER instead of MISSOVER
1) Do NOT use MISSOVER. You almost always want TRUNCOVER instead of MISSOVER.
2) If you have defined an INFORMAT for the variable then you do NOT need to list another informat on the INPUT statement.
3) Do NOT use an INFORMAT with decimal value specified. That tells SAS that if no period is in the data then assume it has an implied decimal point. So if you use an informat of COMMA12.2 and your value is 56 then it will be converted to 0.56 .
4) Do you really want to preserve leading spaces in the character variables?
data test;
length p_term $6 amount 8 moeda_1 $3 ;
format amount comma12.2 ;
informat amount comma12. ;
infile "/home/file.txt" dsd dlm=";" firstobs=2 truncover ;
input p_term -- moeda_1 ;
run;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.