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

I want to import raw data file

file :

1Sep11 389.00 1Oct11 491.00 1Nov11 370.00 1Dec11 335.00
2Sep11 423.00 2Oct11 478.00 2Nov11 407.00 2Dec11 442.00
3Sep11 482.00 3Oct11 300.00 3Nov11 303.00 3Dec11 372.00
4Sep11 407.00 4Oct11 405.00 4Nov11 398.00 4Dec11 465.00

I write a program:

 

FILENAME CALL '/folders/myfolders/sas data_8/Daily_call_duration.txt';

data output
infile call dlm=" ";
input date date9. Call_duration:8.2  @@;
format date date9.;
run;

 

In the output i get

Capture.PNG

I dont understand whats the issue with this,

Any help will appreciate

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Your INPUT statement tells SAS to read EXACTLY 9 characters for each date string. But many of them are shorter than that. So you are leaving the column pointer in the wrong place.

You need to use list mode input style instead.

The simplest change is to add the : (colon) modifier before the format specifications in the INPUT statement.

 

You should also remove the .2 from the informat for duration.  That will cause SAS to divide any values it sees that do not include a period by 100 since you have told SAS that you expect the periods to be missing and that it should assume that the last two digits are the fractional part.  There is actually no need to tell SAS that it needs to use any special informat to read numbers. It already knows how to read numbers.

 

You could also use an INFORMAT statement to let SAS know how to read the dates.

 

So use something like this instead.

input date Call_duration @@;
format date date9.  Call_duration 8.2;
informat date date.;

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Your INPUT statement tells SAS to read EXACTLY 9 characters for each date string. But many of them are shorter than that. So you are leaving the column pointer in the wrong place.

You need to use list mode input style instead.

The simplest change is to add the : (colon) modifier before the format specifications in the INPUT statement.

 

You should also remove the .2 from the informat for duration.  That will cause SAS to divide any values it sees that do not include a period by 100 since you have told SAS that you expect the periods to be missing and that it should assume that the last two digits are the fractional part.  There is actually no need to tell SAS that it needs to use any special informat to read numbers. It already knows how to read numbers.

 

You could also use an INFORMAT statement to let SAS know how to read the dates.

 

So use something like this instead.

input date Call_duration @@;
format date date9.  Call_duration 8.2;
informat date date.;

 

deltaskipper
Fluorite | Level 6

Thanks Tom.

I really appreciate your help.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 2 replies
  • 912 views
  • 1 like
  • 2 in conversation