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

Hello All,

I'm having issue to get log parser values of all log files( for Object Spawner logs) for all end users like SAS EG & AMO. And I'm interested in 6 months or old SAS EG & AMO end users data.

Currently, A byte-order mark in the file
"C:\Users\akhan\Desktop\akhan\ObjectSpawner_2021-10-05_abc_host.log" (for fileref "#LN00008") indicates that the data is encoded in "utf-8". This encoding will be used to process the file. 

I just got values from this log ObjectSpawner_2021-10-05_abc_host.log file only. There are 10 more log files but the pointer only point to 1 log file. Please advise

Attached is the SAS code.

Thank you in advance

Thanks,
Asif

 

Edit by KB, to make the code readable without download:

%macro read_spawnlog;
data spawnlog;
*infile mylib truncover;
infile "C:\Users\akhan\Desktop\akhan\*.log" lrecl=100000000 dsd;
/*filename pth "&libpath";
%put &libpath;*/
format
  datum ddmmyyp10.
  zeit  time8.
  user  $512.
  port  $512.
  address $512.
  success $1.
;
input
zeile $1024.
;
if index(zeile,"New client connection") > 0;
%if "&sysver" = "9.4"
%then %do;
datum = input(substr(zeile,1,10),yymmdd10.);
zeit = input(substr(zeile,12,8),time8.);
%end;
%else %if "&sysver" = "9.2"
%then %do;
datum = input(substr(zeile,1,10),yymmdd10.);
zeit = input(substr(zeile,12,8),time8.);
%end;
%else %if "&sysver" = "9.1"
%then %do;
datum = input(substr(zeile,1,8),yymmdd8.);
zeit = input(substr(zeile,10,8),time8.);
%end;
%else %do;
abort abend 7;
%end;
pos = index(zeile,"server port");
port = substr(zeile,pos+12,4);
pos = index(zeile,"for user");
if pos ne 0
then do;
  user = substr(zeile,pos+9,5);
  pos = indexc(user,".");
  if pos ne 0 then user = substr(user,1,pos-1);
end;
/*else do;
pos = index(zeile,"server port");
port = substr(zeile,pos+12,5);
pos = index(zeile,"for user");
if pos ne 0
then do;
  user = substr(zeile,pos+9,5);
  pos = indexc(user,".");
  if pos ne 0 then user = substr(user,1,pos-1);
end; */
else do;
  pos = index(zeile,"for SAS token user");
  user = substr(zeile,pos+19);
  pos = indexc(user,"@");
  if pos ne 0 then user = substr(user,1,pos-1);
end;
pos = index(zeile,"port are");
%if "&sysver" = "9.4"
%then %do;
address = substr(zeile,pos+17,15);
pos = indexc(address,"]");
if pos > 0 then address = substr(address,1,pos-1);
/*pos = index(APPNAME,"APPNAME");
APPNAME = substr(zeile,pos+283,140);*/
*pos = index(zeile,"904500");
*if pos > 0 then APPNAME = substr(APPNAME,1,pos-1);
*Details = substr(zeile,pos+250);
*pos = indexc(Details,".");
*APPNAME2 = substr(APPNAME,20,23);
*APPNAME2 = index(APPNAME,"SAS Enterprise Guide");
*APPNAME3 = substr(APPNAME2,pos+20);
*APPNAME2 = scan(Details,3);
*APPNAME3 = scan(Details,4);
*APPNAME4 = scan(Details,5);
*SAS_APPLICATION_Names = catx(' ',APPNAME2,APPNAME3,APPNAME4);
*if pos > 0 then Details = substr(Details,1,pos-1);
*where Details contains 'SAS Enterprise Guide';
*APPNAME2 = index(APPNAME,pos+20);
*APPNAME2 = substr(APPNAME,pos+22);
*pos = indexc(APPNAME2,".");
*if pos > 0 then APPNAME = substr(APPNAME,1,pos-1);
%end;
%else %if "&sysver" = "9.2"
%then %do;
address = substr(zeile,pos+17,15);
pos = indexc(address,"]");
if pos > 0 then address = substr(address,1,pos-1);
%end;
%else %do;

address = substr(zeile,pos+9,15);
pos = indexc(address,":");
if pos > 0 then address = substr(address,1,pos-1);
/*%end;
%else %do;*/
/*SASAPP = substr(zeile,pos+9,15);
pos = indexc(SASAPP,":");
if pos > 0 then address = substr(SASAPP,1,pos-1);*/
%end;
if index(zeile,"rejected") > 0 then success = "N"; else success = "Y";
drop pos;
run;
%mend;
%read_spawnlog;

data work.EGClients(drop=zeile);
set work.Spawnlog;
where zeile contains 'SAS Enterprise Guide';
run;
data work.ADDIn (drop=zeile);
set work.Spawnlog;
where zeile contains 'SAS Add-In for Microsoft Office';
run;
title1 "Enterprise Guide End Users Names List";
proc print data=work.EGClients;
run;

title1 "SAS Add-In End Users Names List";
proc print data=work.ADDIn;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Hi!

You should take care to properly copy/paste code from the web, as my code here (which you obviously started with) works. Then start modifying from there.

 

If you need to deal with UTF-encoded files, add the ENCODING= option to the INFILE statement. The LRECL and the size of zeile should only be adjusted if really needed.

View solution in original post

4 REPLIES 4
Patrick
Opal | Level 21

It would help if you'd add the SAS log with mprint and mlogic set.

 

For below portion in your code:

    infile "C:\Users\akhan\Desktop\akhan\*.log" lrecl=100000000 dsd;
    ....
    input
      zeile $1024.
    ;

Your input statement reads up to 1024 characters per row AND it appears you want to read a single row into a single variable Zeile.

  • lrecl should be set to 1024 as you're never reading more than that.
  • dsd makes no sense
  • You need to set TRUNCOVER. The default FLOWOWER is certainly not what you need here.

Your code will read all .log files in folder C:\Users\akhan\Desktop\akhan How many .log files do you have under this folder?

 

To also keep the information from which log file a row comes consider using infile option FILENAME
https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/n1rill4udj0tfun1fvce3j401plo.ht... 

  

 

 

 

 

 

 

 

Asif4862
Quartz | Level 8

Thank you @Patrick for your help & assistance. I appreciate it.

Thanks,
Asif 

Kurt_Bremser
Super User

Hi!

You should take care to properly copy/paste code from the web, as my code here (which you obviously started with) works. Then start modifying from there.

 

If you need to deal with UTF-encoded files, add the ENCODING= option to the INFILE statement. The LRECL and the size of zeile should only be adjusted if really needed.

Asif4862
Quartz | Level 8

Thank you @Kurt_Bremser , your suggested steps did work for me

Thanks,
Asif

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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