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=OMSOBJ:SERVERCOMPONENT/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 [04086681] :sassr - New out call client connection (74065) for user
2015-08-20T00:00:05,092 INFO [04086681] :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 [04086689] 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 -
Date_With_TimeStamp | Status | Processid | userid | Details |
2015-08-20T00:00:05,082 | INFO | [04086681] | :sassrv | New out call client connection (74065) for user |
2015-08-20T00:00:05,092 | INFO | [04086681] | :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 | [04086689] | 74064:datapo@saspw | STP: 36518: Creating New Context |
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.
data log_analysis;
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>
run;
Thanks for any help you offer me.
Hi,
Some tips:
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.
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.
Thanks.
_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:
timestamp=scan(line,1,' ');
status=scan(line,2,' ');
Have a read of the documentation on string manipulation = find, index, scan, substr etc.
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.
data Want;
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;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.