BookmarkSubscribeRSS Feed
Tom
Super User Tom
Super User

I would use PROC APPEND.

 

%macro log_analysis
(filename    /* Physical name of input file */
,data=work.log_analysis /* Name of SAS dataset */
,base=log.log_analysis /* Name of the Master dataset */
);

data &data;
  length fname $400;
   infile "&filename" dsd truncover END = end_of_file LRECL=32000;
   fname="&filename" ;
...
run;

proc append data=&data base=&base force;
run;
%mend log_analysis;
Babloo
Rhodochrosite | Level 12

I've another question. How will you pass values to the maco paramter 'filename'? I need to pass values from the other macro (filelist) to the macro parameter 'filename' instead of explicitly defining the values. I did tried like below,

 

In the code below,filename resolves to SASApp_STPServer_2015-10-01_18208.lo​g and SASApp_STPServer_2015-10-04_tmptcmsaslva2_19142.lo​g. These two .log files are different file and I was expecting SAS to process the file one-by-one and then need to consolidate to one master dataset log.log_analysis. When I ran the code below, SAS was trying to search both the file at the same moment and it failed as it could not find both the file in a single data step.

 

Could

proc sql noprint;
select distinct fname into :filelist separated by ' '
from log.output_file;
quit;

%put &filelist;


%macro log_analysis
(filename =&filelist  /* Physical name of input file */
,data=work.log_analysis /* Name of SAS dataset */
,base=log.log_analysis /* Name of the Master dataset */
);

data &data;
set log.output_file;
length fname $400;
infile "/usr/sas/sas_config/Lev1/SASApp/StoredProcessServ​er/Logs/&filename" dsd truncover  END = end_of_file LRECL=32000;
fname="&filename" ;
DO WHILE (not end_of_file);
input var : $ 3000.;
var1 = _infile_;
if var1 = :'201' then do;
...........
...........
output;
end;
end;
run;

proc append data=&data base=&base force;
run;

%mend log_analysis;

data _null_;
  set log.output_file;
  if fname =: 'SASApp_STPServer' then call execute ('%log_analysis;');
else put 'no log files';
run;

you guide me how to achive this task? Please be informed that the macro filelist is also resolves to SASApp_STPServer_2015-10-01_tmptcmsaslva2_18208.lo​g and SASApp_STPServer_2015-10-04_tmptcmsaslva2_19142.lo​g

 

 

Log:

 


NOTE: CALL EXECUTE generated line.
1         + data work.log_analysis;  set log.output_file;    length fname $400;  infile 
"/usr/sas/sas_config/Lev1/SASApp/StoredProcessServ​er/Logs/SASApp_STPServer_2015-10-01_18208.log 
SASApp_STPServer_2015-10-04_19142.log" dsd truncover
2         + END = end_of_file LRECL=32000;  fname="SASApp_STPServer_2015-10-01_tmptcmsaslva2_1​8208.log 
SASApp_STPServer_2015-10-04_19142.log" ;  DO WHILE (not end_of_file);  input var : $ 3000.;    var1 = _infile_;  if 
var1 = :'201' then do;
3         + Date_TimeStamp= scan(var1,1," ");  Status = scan(var1,2," ");  Processid = scan(var1,3," ");  userid = scan(var1,4," 
");  Details = scan(var1,-1,'-');  output;  end;  end;  drop var var1;  run;

ERROR: Physical file does not exist, 
       /usr/sas/sas_config/Lev1/SASApp/StoredProcessServe​r/Logs/SASApp_STPServer_2015-10-01_18208.log 
       SASApp_STPServer_2015-10-04_19142.log.
NOTE: The SAS System stopped processing this step because of errors.

Thanks for any help you offer me.

 

Babloo
Rhodochrosite | Level 12
How does the macro variable &base will get resolve? Because it was declared in your example.

Thanks again for your continued support.
Tom
Super User Tom
Super User

A macro variable gets resolve when you reference with &.  So %PUT &BASE will write the value of BASE to the log.

A macro variable gets assigned a value in a number of ways.

%let base=fred;

... call symputx('base','fred'); ...

... select 'fred' into :base ....

In the context of call a macro the parmeters (which are really just macro variables that are local to the macro) the value assigned is based on how you call it.  

If you specify a value on the macro call , %mymacro(base=fred), then that is the value assigned.

If have defined it with a default value in the macro definition then if you call the macro wihout specifying a value it will use the defualt value.

%macro mymacro(base=george); %put &base; %mend mymacro;

 %mymacro; 
 george
 %mymacro(base=fred);
 fred

If you want to override the default and set the value to an empty string then include it in the macro call. %mymacro(base=);

 

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
  • 18 replies
  • 8850 views
  • 8 likes
  • 4 in conversation