BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Batman
Quartz | Level 8

I have several multi-dimensional arrays I need to use in a very large dataset.   Rather than trying to merge them, I thought it might be more efficient to create macro arrays and them selectively assign macro values in the large data set with do loops.   However, I've run into an issue.   The Do Loop is not "1 to X" but rather "2006 to 2014."    %eval will not read my formula (see row 30).   Any suggestions on a better way?

 

26 %let DedV1_list=472 495 516 524 538 540 540 550;

27 Data _null_;

28 Year=2007;

29 %macro rap;

30 %let Ded=%scan(&DedV1_list,%eval(year-2006));

31 %put &DEd;

32 %mend;

33 %rap

SYMBOLGEN: Macro variable DEDV1_LIST resolves to 472 495 516 524 538 540 540 550

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:

year-2006

WARNING: Argument 2 to macro function %SCAN is out of range.

ERROR: The macro RAP will stop executing.

34 run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Not sure you should be putting data into macro variables, but your example looks pretty simple.

You could just use a SCAN() function.

%let DedV1_list=472 495 516 524 538 540 540 550;

data want ;
  set have ;
  ded = input(scan("&dedv1_list",year - 2006),32.);
run;

Or you could make a temporary array in your data step.

data want ;
  array dedv1_list (%sysfunc(countw(&dedv1_list))) _temporary_ (&dedv1_list);
  set have ;
  ded = dedv1_list(year - 2006) ;
run;

View solution in original post

2 REPLIES 2
Reeza
Super User

You shouldn't embed a macro within a data step. You're mixing data step and macro logic. So...what are you trying to do overall? 

 

I think a temporary array may be a better solution - use the macro variable to create the array if you like. 

 

Array myNum(*) _temporary_ (&devv1_list);  

 

dev1 = myNum(year - 2006);

 

call symputx('dev1', dev1, 'g');

 

run;

 

%put &dev1;

Tom
Super User Tom
Super User

Not sure you should be putting data into macro variables, but your example looks pretty simple.

You could just use a SCAN() function.

%let DedV1_list=472 495 516 524 538 540 540 550;

data want ;
  set have ;
  ded = input(scan("&dedv1_list",year - 2006),32.);
run;

Or you could make a temporary array in your data step.

data want ;
  array dedv1_list (%sysfunc(countw(&dedv1_list))) _temporary_ (&dedv1_list);
  set have ;
  ded = dedv1_list(year - 2006) ;
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 616 views
  • 0 likes
  • 3 in conversation