BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
KOUAME
Obsidian | Level 7

HI, Trying to import my data but get a problem with the date format, can anyone helps me:

You will find the data attached and my code:

 

 

 

data client;

infile"C:\Users\KOUAME\Downloads\clients.txt" missover firstobs = 2;
input PRENOM$ 1-11 NOM:$ 14-27 DAT_NAI 27-37 VILLE$ 39-47 DEPT 48-49 ACHATS 53-54 @58 ANCIENNETE ;

format DAT_NAI ddmmyy10.;
informat DAT_NAI ddmmyy10.;

format ANCIENNETE comma3.1;
informat ANCIENNETE comma3.1;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

If you use a column range in the INPUT statement then you cannot use a specific informat.  SAS will just use normal $w. informat for character variables and w. informat for numeric variables.  So instead of using a column range just use @ nn to position the pointer before the value and then you can use an informat.  Also since your data is fixed column you should include the informat in the INPUT statement to prevent it from running over missing values and finding the next character to read.  Adding the INFORMAT statement is optional.

 

Also do NOT include a number of decimal places in an INFORMAT unless your source strings have explicitly been generated with the decimal point indicator character removed.  Otherwise integer values will be divided by that power of 10 to insert the implicit decimal point.

 

Also do NOT use the older MISSOVER option, instead use the newer TRUNCOVER option. Your example is exactly the case where it can make a big difference.  Consider the case where your informat uses width of 3 bytes starting in column 60 and the text file only has 2 characters there.  With MISSOVER the variable will be missing. With TRUNCOVER the informat will read the 2 characters.

 

data client;
  *infile"C:\Users\KOUAME\Downloads\clients.txt" missover firstobs = 2;
  infile cards truncover firstobs=2;
  input PRENOM $ 1-11 NOM $ 14-27 @29 DAT_NAI ddmmyy10.
        VILLE $ 39-47 DEPT 48-49 ACHATS 53-54 
        @60 ANCIENNETE comma3.
  ;
  format DAT_NAI ddmmyy10.;
  informat DAT_NAI ddmmyy10.;
  format ANCIENNETE comma3.1;
  informat ANCIENNETE comma3.;
cards;
PRENOM       NOM            DAT_NAI    VILLE   DEPT ACHATS ANCIENNETE
Anne Sophie  Martineau      14/08/1955 PARIS   75   8      0,3
Marie-Anne   Dupont         01/12/1977 ORLEANS
Roger        Martin du Gard 18/01/1988         29   17     1,8
;
proc print;
run;

 

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

@KOUAME wrote:

HI, Trying to import my data but get a problem with the date format ...


What problem? Please describe in detail, and if possible, show us.

--
Paige Miller
KOUAME
Obsidian | Level 7

Rykouame_0-1602508557540.png

when I execute it gives this table with missing values in DAT_NAI.

Tom
Super User Tom
Super User

If you use a column range in the INPUT statement then you cannot use a specific informat.  SAS will just use normal $w. informat for character variables and w. informat for numeric variables.  So instead of using a column range just use @ nn to position the pointer before the value and then you can use an informat.  Also since your data is fixed column you should include the informat in the INPUT statement to prevent it from running over missing values and finding the next character to read.  Adding the INFORMAT statement is optional.

 

Also do NOT include a number of decimal places in an INFORMAT unless your source strings have explicitly been generated with the decimal point indicator character removed.  Otherwise integer values will be divided by that power of 10 to insert the implicit decimal point.

 

Also do NOT use the older MISSOVER option, instead use the newer TRUNCOVER option. Your example is exactly the case where it can make a big difference.  Consider the case where your informat uses width of 3 bytes starting in column 60 and the text file only has 2 characters there.  With MISSOVER the variable will be missing. With TRUNCOVER the informat will read the 2 characters.

 

data client;
  *infile"C:\Users\KOUAME\Downloads\clients.txt" missover firstobs = 2;
  infile cards truncover firstobs=2;
  input PRENOM $ 1-11 NOM $ 14-27 @29 DAT_NAI ddmmyy10.
        VILLE $ 39-47 DEPT 48-49 ACHATS 53-54 
        @60 ANCIENNETE comma3.
  ;
  format DAT_NAI ddmmyy10.;
  informat DAT_NAI ddmmyy10.;
  format ANCIENNETE comma3.1;
  informat ANCIENNETE comma3.;
cards;
PRENOM       NOM            DAT_NAI    VILLE   DEPT ACHATS ANCIENNETE
Anne Sophie  Martineau      14/08/1955 PARIS   75   8      0,3
Marie-Anne   Dupont         01/12/1977 ORLEANS
Roger        Martin du Gard 18/01/1988         29   17     1,8
;
proc print;
run;

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1340 views
  • 0 likes
  • 3 in conversation