Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing Help

Status
Not open for further replies.

ja01

Technical User
Dec 14, 2005
48
0
0
US
In a sas.log file I have the following:
smith (data type is text or $)
2006-03-02:00:00:00 (data type is date time)
my report (data type is text or $)
The log file lists everything vertical or 1 line for each entry

Issue#1 : I need to parse the data into sas and create a table that looks like this: smith 03/02/06 my report
Essentially I need to display data from the sas.log table horizontally not vertically.

Issue#2: The entry "my report" is an example of how some of the entries have spaces in it. SAS cuts off data like this when it encounters a space

Issue#3: I want to display the date as a simple short date format (ie 3/2/07)
The sas.log is in my c drive, so I need to read it into SAS

Here is the code I have so far:
data
'c:\myname'; "The nameI want to give the file"
infile 'c:\reports.sas "The location of the file.
input name$ 1-30/Date yymmdd 10./reportname$ 1-30;
run;
Am I missing something here because the data does not come out formatted. I seem to get stumped with the date.
 
You would need to use the line pointer and line hold type characters I think for this (look up the "trailing @").
Alternatively, the way I'd do this is to read in each line and process it separately. This should do the trick, or at least put you on the right path.
Code:
data test;
  infile blah ....;

  length fullrec $50
         name $20
         date 6
         reportname $30;
  retain counter 0
         name
         date
         reportname;

  counter +1 ;

  input fullrec;

  if counter = 1 then name = substr(fullrec,1,30);
  else if counter = 2 then date = input(substr(fullrec,1,10),yymmdd10.);
  else if counter =3 then
  do;
    reportname = substr(fullrecl,1,30);
    output;
    counter = 0;
    date = .; reportname = ''; name = '';
  end;
run;



Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top