BookmarkSubscribeRSS Feed
Filipvdr
Pyrite | Level 9

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

5 REPLIES 5
ScottBass
Rhodochrosite | Level 12

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...


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
DF
Fluorite | Level 6 DF
Fluorite | Level 6

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

data_null__
Jade | Level 19

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)||'));');

Filipvdr
Pyrite | Level 9

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;

data_null__
Jade | Level 19

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)||"));");

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 747 views
  • 0 likes
  • 4 in conversation