Hi All,
Can you tell me why my macro variable records is not resolving inside the macro %import_file.
It resolves outside to 3.
********************************************** Please find log***************
27 %macro Import_File(records);
28 %put 'hiiiiiii' %nrstr(&records.) ;
30 %if %nrstr(&records.) > 0 %then
31 %do;
32
33 data _null_;
34 set wash_file;
35 call symput ('file_date',strip(file_date));
36 call symput ('file_name',strip(file_name));
37 call symput ('file_upload_date',file_upload_date);
38 select (actual_file_name);
40 when ('bbb') rc=dosubl('%Import_StrategicFile(&file_name,&file_upload_date,ee)');
41 when ('ccc') rc=dosubl('%Import_StrategicFile(&file_name,&file_upload_date,ddd)');
42 end;
43 run;
44
45 %end;
46 %else
47 %do;
48
49 data _null_;
50 rc=dosubl('%folder_empty_message()');
51 run;
52
53 %end;
54 %mend;
55
57 %put &Records;
3
58 %Import_File(records);
Hi @dennis_oz
The use of the %nrstr() function prevents the resolution of the macrovariable.
->Remove it and run the code.
😳..my bad again..
What if you remove %nrstr() and adapt the macro call as suggested by @ballardw ?
%macro Import_File(3);
it works when those changes are incorporated
When you have a question about macro code behaving then you want to test your code with the options MPRINT and possibly SYMBOLGEN and MLOGIC to follow the code.
Then read the log for the generated code.
Since your call to the macro does not use the macro variable &records:
57 %put &Records; 3 58 %Import_File(records); <= NOT THE MACRO VARIABLE &RECORDS
You have passed the text "records" as the parameter. Since the macro has a parameter named Records it will use the local version and not the macro variable "records" created outside of the macro definition.
If you want to use the existing macro value in &records then the call would be
%import(&records)
Really bad practice to expect to expect to use a macro value not passed as a parameter.
😳.my bad
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.