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

HI,

I've data as below and embedded with multiple spaces between time and number columns data. Please let me know how to read this inconsistent "ID" column data

 

SNO, DATE, TIME,ID, NUMBER, COST, DISCOUNT
0 26/08/2010 16:33:36 LOC MH 5533442211 42 0.90
1 26/08/2010 16:34:29 LOC MH 5533442212 14 0.90
2 26/08/2010 16:35:20 9422 5533442213 74 1.80
3 28/08/2010 12:13:38 CHI - MH 5533442214 41 0.90
4 28/08/2010 12:59:20 9823 5533442215 15 0.90

1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15

You could play with the `_infile_` and scan() function:

data want;
  input;
  length SNO $ 8 DATE TIME 8 ID $ 32 NUMBER COST DISCOUNT 8 _time _number $ 20;
  format DATE yymmdd10. TIME time9.;

  SNO = scan (_infile_, 1, " ");
  DATE = input( scan (_infile_, 2, " "), ddmmyy10.);
  _TIME = scan (_infile_, 3, " ");
  TIME = input(_TIME, time9.);
  _NUMBER = scan (_infile_, -3, " "); 
  NUMBER = input(_NUMBER, best32.);
  COST = input( scan (_infile_, -2, " "), best32.); 
  DISCOUNT = input( scan (_infile_, -1, " "), best32.);

  _n = find(_infile_, _TIME, "T") + 8;
  _m = find(_infile_, _NUMBER, "T");
  ID = substr(_infile_, _n, _m - _n);

  drop _:;
cards;
0 26/08/2010 16:33:36 LOC MH 5533442211 42 0.90
1 26/08/2010 16:34:29 LOC MH 5533442212 14 0.90
2 26/08/2010 16:35:20 9422 5533442213 74 1.80
3 28/08/2010 12:13:38 CHI - MH 5533442214 41 0.90
4 28/08/2010 12:59:20 9823 5533442215 15 0.90
;
run;

all the best

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

Is that really what you have in the file?

The header is comma-separated, but the data is not.

I suggest that you view the file with a pure text editor (Windows Editor or Notepad++) and copy/paste the first few lines into a window opened with the indicated button:

Bildschirmfoto 2020-04-07 um 08.32.59.jpg

 

This will give us a clearer picture of what you are dealing with.

yabwon
Onyx | Level 15

You could play with the `_infile_` and scan() function:

data want;
  input;
  length SNO $ 8 DATE TIME 8 ID $ 32 NUMBER COST DISCOUNT 8 _time _number $ 20;
  format DATE yymmdd10. TIME time9.;

  SNO = scan (_infile_, 1, " ");
  DATE = input( scan (_infile_, 2, " "), ddmmyy10.);
  _TIME = scan (_infile_, 3, " ");
  TIME = input(_TIME, time9.);
  _NUMBER = scan (_infile_, -3, " "); 
  NUMBER = input(_NUMBER, best32.);
  COST = input( scan (_infile_, -2, " "), best32.); 
  DISCOUNT = input( scan (_infile_, -1, " "), best32.);

  _n = find(_infile_, _TIME, "T") + 8;
  _m = find(_infile_, _NUMBER, "T");
  ID = substr(_infile_, _n, _m - _n);

  drop _:;
cards;
0 26/08/2010 16:33:36 LOC MH 5533442211 42 0.90
1 26/08/2010 16:34:29 LOC MH 5533442212 14 0.90
2 26/08/2010 16:35:20 9422 5533442213 74 1.80
3 28/08/2010 12:13:38 CHI - MH 5533442214 41 0.90
4 28/08/2010 12:59:20 9823 5533442215 15 0.90
;
run;

all the best

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



sas-innovate-2024.png

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.

 

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
  • 2 replies
  • 350 views
  • 0 likes
  • 3 in conversation