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;

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
  • 1121 views
  • 0 likes
  • 3 in conversation