BookmarkSubscribeRSS Feed
dennis_oz
Quartz | Level 8

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

6 REPLIES 6
ed_sas_member
Meteorite | Level 14

Hi @dennis_oz 

 

The use of the %nrstr() function prevents the resolution of the macrovariable.

->Remove it and run the code.

dennis_oz
Quartz | Level 8

😳..my bad again..

ed_sas_member
Meteorite | Level 14

What if you remove %nrstr() and adapt the macro call as suggested by @ballardw ?

%macro Import_File(3);
dennis_oz
Quartz | Level 8

it works when those changes are incorporated

ballardw
Super User

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.

 

dennis_oz
Quartz | Level 8

😳.my bad

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 6 replies
  • 840 views
  • 2 likes
  • 3 in conversation