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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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