Hello again,
next problem is I pass a filereference in a call execute, but I get an error:
When I pass for example the fileid and uncomment the first part and comment the second part in the macro then it works!
So i could pass the fileid and get the fileref from dataset files as well, but i would like to pass the fullfilename.
Filepath Looks like: (it works when i just pass that to the macro)
/imc/other/osp/wom/ExportedMeasurements1_data.txt
%macro ReadFiles(fullfilename);
/*
data test&fileid;
set files;
where fileid = &fileid;
run;
*/
%if %sysfunc(fileexist(&fullfilename)) %then %do;
%put The external file &fullfilename does exist.;
%end;
%else %do;
%put Error &fullfilename;
%end;
%mend;
data _null_;
format fullfile $200.;
set files;
if fullfile ne '' then call execute ("%ReadFiles("||trim(fullfile)||");");
run;
i also tried with strip and compress but always get this kind of error:
Error "||trim(fullfile)||" (so it does not existis and it prints Error &fullfilename
This is just a guess but try putting '%ReadFiles(' in single quotes. My guess is %ReadFiles is getting expanded during the compilation of the data step, and the resolved code is getting call executed. You want to mask the expansion of %ReadFiles, so it is just a macro code with your desired parameter when call executed.
HTH...
Was going to suggest the same thing. The online documention explaines the difference: http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000543697.htm
Many times perhaps most of the time you will also want to delay execution of the MACRO until after the data step is done using %NRSTR
call execute('%nrstr(%ReadFiles('||trim(fullfile)||'));');
thanks all for your replies, do any of you guys know of it is possible to call execute from within a macro?
%macro ReadFiles(fullfilename,name,curve,dark);
%if "&curve" eq "Y" and "&DARK" eq "N" %then %do;
proc import datafile=&fullfilename
out=&name
dbms=dlm
replace;
delimiter='09'x;
datarow=2;
run;
Proc contents data = &name out = temp_&name varnum; run;
data temp_&name;
set temp_&name(keep=name varnum);
run;
proc sort data=temp_&name;
by varnum;
run;
data temp_&name;
set temp_&name;
if mod(_n_,2) =1 then count+1;
run;
data test_&name;
set temp_&name;
by count;
length list $ 100;
retain list;
if first.count then do;
flag+1;
call missing(list);
end;
list=catx(' ',list,name);
A = scan(list,1);
B = scan(list,2);
if last.count and B ne '' then do;
call execute ("%AppendCurve("||strip(flag)||","||strip(A)||","||strip(B)||","||strip(list)||");");
end;
run;
%end;
%if "&curve" eq "N" and "&DARK" eq "N" %then %do;
proc import datafile=&fullfilename
out=&name
dbms=dlm
replace;
delimiter='09'x;
datarow=3;
run;
data &name( drop=Run_Id Device rename=(VAR25=Slope_Voc));
format Curve_Id;
set &name;
run;
proc append base=Edc_wacom data=&name force; run;
data edc_wacom;
set edc_wacom;
Curve_id = _N_;
run;
%end;
%mend;
If you're asking what wrong with this macro it's the same thing double quotes. Plus you probably want %NRSTR
call execute ('%NRSTR(%AppendCurve('||strip(flag)||","||strip(A)||","||strip(B)||","||strip(list)||"));");
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.