BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Kiteulf
Quartz | Level 8
proc import file="\xxxx\test.txt"
    out=work.ISRdata
    dbms=tab
	replace;GETNAMES=NO
   ;guessingrows =10000; 
    delimiter='09'x;
;
run;

It doesn't get the commas right, it moves them one to the left.

 

Var7 is 201,836 ?

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Why are you using PROC IMPORT to read a file that does not have column headers and which has only 19 variables?

Just write your own data step to read it.

Then you can set the NAMES, TYPES, LENGTHS for the variables and tell SAS which INFORMAT to use when reading those numbers that are using commas where periods are expected.

Looks like the first 5 variables are identifiers so read them as character strings.

If you want to force SAS to treat commas as meaning a decimal point use the COMMAX informat.

1561  data test;
1562    infile 'c:\downloads\test.txt' dlm='09'x dsd truncover firstobs=1 ;
1563    length VAR1 $3 VAR2 $6 VAR3 $6 VAR4 $2 VAR5 $6 VAR6-VAR19 8;
1564    informat VAR6-VAR19 commax.;
1565    input VAR1 -- VAR19 ;
1566    if _n_=1 then list;
1567  run;

NOTE: A byte-order mark in the file "c:\downloads\test.txt" (for fileref "#LN00140") indicates that the data is encoded in "utf-8".
      This encoding will be used to process the file.
NOTE: The infile 'c:\downloads\test.txt' is:
      Filename=c:\downloads\test.txt,
      RECFM=V,LRECL=131068,File Size (bytes)=116,
      Last Modified=10 février 2022 11 h 29,
      Create Time=10 février 2022 11 h 29

RULE:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0

1   CHAR  NOR.202001.689432.CC.K01_VG.1.2018,36.2018,36.2018,36.1257,93.0,00.0,00.1717,29.664,09.0,00.0,00.0,0
    ZONE  4450333333033333304404335540303333233033332330333323303333233032330323303333233033323303233032330323
    NUMR  EF2920200196894329339B01F679192018C3692018C3692018C3691257C9390C0090C0091717C299664C0990C0090C0090C0

     101  0.0,00.0,00 111
    ZONE  30323303233
    NUMR  090C0090C00
NOTE: 1 record was read from the infile 'c:\downloads\test.txt'.
      The minimum record length was 111.
      The maximum record length was 111.
NOTE: The data set WORK.TEST has 1 observations and 19 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.01 seconds


1568
1569  data _null_;
1570    set test (obs=1);
1571    put (_all_) (=/);
1572  run;


VAR1=NOR
VAR2=202001
VAR3=689432
VAR4=CC
VAR5=K01_VG
VAR6=1
VAR7=2018.36
VAR8=2018.36
VAR9=2018.36
VAR10=1257.93
VAR11=0
VAR12=0
VAR13=1717.29
VAR14=664.09
VAR15=0
VAR16=0
VAR17=0
VAR18=0
VAR19=0
NOTE: There were 1 observations read from the data set WORK.TEST.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


 

View solution in original post

2 REPLIES 2
ballardw
Super User

Look at the LOG. There should be data step code generated that will show the informat used to read the values.

It may help to copy from the log that data step and paste it into a text box opened on the forum using the </> icon so we can see details.

 

I am going to guess, since you don't provide what is meant by "wrong" , that the commas are supposed to separate the integer portion of a number from the decimal portion. Is that what is supposed to happen?

This is possibly a result of the NLS (National Language Settings) in effect as well.

You might want to run this code and then show us what the result is that appears in the log.

Proc options option=locale;
run;

For example on my system it shows:

LOCALE=EN_US      Specifies a set of attributes in a SAS session that reflect the language,
                   local conventions, and culture for a geographical region.

The rules used for "local conventions" can affect how commas are read and treated.

Tom
Super User Tom
Super User

Why are you using PROC IMPORT to read a file that does not have column headers and which has only 19 variables?

Just write your own data step to read it.

Then you can set the NAMES, TYPES, LENGTHS for the variables and tell SAS which INFORMAT to use when reading those numbers that are using commas where periods are expected.

Looks like the first 5 variables are identifiers so read them as character strings.

If you want to force SAS to treat commas as meaning a decimal point use the COMMAX informat.

1561  data test;
1562    infile 'c:\downloads\test.txt' dlm='09'x dsd truncover firstobs=1 ;
1563    length VAR1 $3 VAR2 $6 VAR3 $6 VAR4 $2 VAR5 $6 VAR6-VAR19 8;
1564    informat VAR6-VAR19 commax.;
1565    input VAR1 -- VAR19 ;
1566    if _n_=1 then list;
1567  run;

NOTE: A byte-order mark in the file "c:\downloads\test.txt" (for fileref "#LN00140") indicates that the data is encoded in "utf-8".
      This encoding will be used to process the file.
NOTE: The infile 'c:\downloads\test.txt' is:
      Filename=c:\downloads\test.txt,
      RECFM=V,LRECL=131068,File Size (bytes)=116,
      Last Modified=10 février 2022 11 h 29,
      Create Time=10 février 2022 11 h 29

RULE:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0

1   CHAR  NOR.202001.689432.CC.K01_VG.1.2018,36.2018,36.2018,36.1257,93.0,00.0,00.1717,29.664,09.0,00.0,00.0,0
    ZONE  4450333333033333304404335540303333233033332330333323303333233032330323303333233033323303233032330323
    NUMR  EF2920200196894329339B01F679192018C3692018C3692018C3691257C9390C0090C0091717C299664C0990C0090C0090C0

     101  0.0,00.0,00 111
    ZONE  30323303233
    NUMR  090C0090C00
NOTE: 1 record was read from the infile 'c:\downloads\test.txt'.
      The minimum record length was 111.
      The maximum record length was 111.
NOTE: The data set WORK.TEST has 1 observations and 19 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.01 seconds


1568
1569  data _null_;
1570    set test (obs=1);
1571    put (_all_) (=/);
1572  run;


VAR1=NOR
VAR2=202001
VAR3=689432
VAR4=CC
VAR5=K01_VG
VAR6=1
VAR7=2018.36
VAR8=2018.36
VAR9=2018.36
VAR10=1257.93
VAR11=0
VAR12=0
VAR13=1717.29
VAR14=664.09
VAR15=0
VAR16=0
VAR17=0
VAR18=0
VAR19=0
NOTE: There were 1 observations read from the data set WORK.TEST.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 467 views
  • 1 like
  • 3 in conversation