Hello! Im wondering if there is a way to include the filename in the output for proc mean. I have a loop that does proc mean for a series of files, but in the output I only get the varname to identify each output I would also like to add the file name
%macro do_nftest (allanftest);
%do p=1 %to %sysfunc(countw(&allanftest));
proc means data= %scan(&allanftest,&p);
var fr11;
run;
%end;
%mend;
%do_nftest(&allanftest.);
Thankful for any help!
Hi,
Can you provide example of your data, and example of your output as its not clear just from the code. If you want the dataset name in the output then a simple change of mindset from repeating code to setting your data together and by group processing it. E.g.
I have three datasets A, B, C:
data for_test;
set a (in=a) b (in=b) c (in=c);
length dataset_name $8;
if a then dataset_name="A";
else if b then dataset_name="B";
else dataset_name="C";
run;
proc means data=for_test;
by dataset_name;
var fr11;
output out=results n=n ...;
run;
As you can see form the above, I combine my data, then run one proc means with a by grouping on it. This is both easier to code, and is better performance, no need for macro code at all.
Nice, I always forget the indsname option.
I don't know if this meets your needs, but you could easily put the filename in the title.
title "Using Data Set %scan(&allanftest,&p)";
Hi Caroline,
You can do this by making a table list of the files in that directory, then you substr() the
var to get only the file name, create a variable as an ID that set first file as 1 and so on.
The syntax would be similar to this:
filename file "ls /path/*.txt"; data test; length entire_row $ 160; infile file; input entire_row; run; data test2; set test; id = _N_; new_row = substr(entire_row,1,1); run; /*Here create a macro with %do loop to recognize the id*/ proc sql noprint; select new_row into: nfile&i. from test2 where id = &i.; quit;
In proc sql create a macro step to create multiple macros containing file names.
After this use in your proc means %do loop, i would say to put in the same
%do loop to do this.
Hope this helps
Att
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.