BookmarkSubscribeRSS Feed
TomNYCKid
Calcite | Level 5

Upfront... just want to say thanks for the help...

I have the following code snipet for assigning values from a dataset to an array... I get an error message about converting numeric values to char values. I have not been able to find a solution to this. Would greatly appreciate any help...

---------------------------------------------------------------------------

%macro DefineInputArray;
      ARRAY BYLINE(48) $16.  BYLINE1 - BYLINE50;
%mend;

data sims;

set data_inputs;
%DefineInputArray;

format iter BEST.;
do i=1 to 50;
  %let iter = 1000+(i-1)*1000;
  BYLINE(i) = iVALUE&iter .;
end;


run;

---------------------------------------------------------------------------

NOTE: Numeric values have been converted to character values at the places given by:      (Line):(Column).

---------------------------------------------------------------------------

2 REPLIES 2
MumSquared
Calcite | Level 5

Try using %eval() with the %let statement:

  %let iter = %eval(1000+(i-1)*1000);

Patrick
Opal | Level 21

You will have a timing issue when using a macro %let statement in a data step. The %let statement will get executed before the data step so it won't be part of the data step iteration and you also can't pass a SAS data step variable to the %let statement. There your "i" will simply be interpreted as the character 'i'.

Not sure why you need a macro at all but as this is a code snippet reality might look different and there are good reasons for a macro. Below should make your code snippet work:

%macro DefineInputArray;

      ARRAY BYLINE(50) $16.  BYLINE1 - BYLINE50;

   array iVal (50)

   %do i=1 %to 50;

     %let iter = %eval(1000+(&i-1)*1000);

  iVALUE&iter

   %end;

    %str(;)

%mend;

data sims;

  set data_inputs;

  %DefineInputArray;

  do i=1 to dim(BYLINE);

   BYLINE = iVALUE;

  end;

run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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