08-20-2015 05:47 AM
I've a .log file (for example) as below.
Host: 'tmptcmsaslva2', OS: 'LIN X64', Release: '2.6.32-431.3.1.el6.x86_64', SAS Version: '9.03.01M2P08152012', Command: '/usr/sas/sas9.3/SASFoundation/9.3/sasexe/sas -noterminal -netencryptalgorithm SASProprietary -metaserver tmptcmsaslva2.timeinc.com -metaport 8561 -metarepository Foundation -objectserver -objectserverparms "protocol=bridge spawned spp=45106 cid=0 classfactory=15931E31-667F-11D5-8804-00C04F35AC8C server=OMSOBJERVERCOMPONENT/A52GREI3.AV000006 cel=credentials dnsMatch=tmptcmsaslva2.timeinc.com multiuser port=8611 lb saslangrunas=client applevel=3"'
Log continued from /usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_2015-08-19_tmptcmsaslva2_19142.log
2015-08-20T00:00:05,082 INFO  :sassr - New out call client connection (74065) for user
2015-08-20T00:00:05,092 INFO  :datapo@saspw - New client connection (74064) accepted from server port 8611 for SAS token user Encryption level is Credentials using encryption algorithm SASPROPRIETARY. Peer IP address and port are [10.176.232.41]:39494.
2015-08-20T00:00:05,094 INFO  74064:datapo@saspw - STP: 36518: Creating New Context
In this log file I need to read the records from line number 6 and I need to produce the output as below. Please note that the field 'userid' is not a fixed width delimited. The value should be read before the hyphen -
|2015-08-20T00:00:05,082||INFO||||:sassrv||New out call client |
connection (74065) for user
|2015-08-20T00:00:05,092||INFO||||:datapo@saspw||New client connection |
(74064) accepted from server port 8611 for SAS token user Encryption level is
Credentials using encryption algorithm SASPROPRIETARY. Peer IP address
and port are [10.176.232.41]:39494
|2015-08-20T00:00:05,094||INFO||||74064:datapo@saspw||STP: 36518: Creating |
I tried the code like below, but it not producing the output as I look for. Need some tips (or code) to accomplish this task effectively.
infile '/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_2015-08-19_tmptcmsaslva2_19142.log' firstobs=6 dsd truncover;
input Date_With_TimeStamp $ 1-23 Status $ 25-28 Processid $
31-38 userid @ ;
<need code to extract this field as per the rules said above>
Thanks for any help you offer me.
08-20-2015 06:24 AM
Read the file in as a whole:
input line $2000;
Then use an if statement:
if _n_=6 then do; ... end;
Then split line up based on your crtieria, using string find and substring commands.
08-20-2015 06:28 AM
Thanks for your tips.
What is '6' in your code? May I request you to elaborate your tips?
I was looking for the do loop where you mentioned as ..
It would be great if you can help me to complete the do loop.
08-20-2015 06:46 AM
_n_ refers to the observation number, I took six from your text "In this log file I need to read the records from line number 6".
Afraid I don't have time for a complete parsing program, date with timestamp should be straightforward you can probably scan() most of them:
Have a read of the documentation on string manipulation = find, index, scan, substr etc.
08-20-2015 06:43 AM
When I copy your records it looks like you start at line 4 not 6 and you need to include LRECL option to unsure your records are not truncated. The records can be read with blank delimited list input until you get to DETAILS and then you just want the rest of the records so you can switch to formatted input and let TRUCOVER keep you from FLOWingOVER.
08-20-2015 07:01 AM
infile "path\filename.txt" dlm='^';
input var : $ 3000.;
var1 = _infile_;
if var1 = :'2015';
Date_With_TimeStamp = scan(var1,1," ");
Status = scan(var1,2," ");
Processid = scan(var1,3," ");
userid = scan(var1,4," ");
Details = scan(var1,-1,'-');
drop var var1;