BookmarkSubscribeRSS Feed
DartRodrigo
Lapis Lazuli | Level 10

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:

infile1.png

But when i use the import wizard formating it the same way it works and i get this:

infile2.png

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

7 REPLIES 7
PGStats
Opal | Level 21

Try

INPUT

        P_TERM           :$6.

        amount           :COMMA12.

        Moeda_1          :$3. ;


PG

PG
DartRodrigo
Lapis Lazuli | Level 10

I tested, not works.

Tks

Reeza
Super User

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;

DartRodrigo
Lapis Lazuli | Level 10

Not working.

Reeza
Super User

Attach sample data.

Reeza
Super User

Try TRUNCOVER instead of MISSOVER

Tom
Super User Tom
Super User

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 636 views
  • 1 like
  • 4 in conversation