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

Dear Community,

My macro is looping through an array of numbers. 

%let cutoff = 90 95 96 96.5;

The macro works just fine for the integers, but not for the numbers with decimal marks.  For 96.5, the macro thinks that it is 2 separate numbers - 96 and 5.

The %STR and %NRSTR functions do not mask periods. 

How can I make the macro to recognize 96.5 properly? 

I think that a masking macro function is needed, but I can't fine one.

Thanks,

Eric

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You will need to provide more about how you are using the values.

Perhaps you are using the %SCAN() function?  The default delimiters for %SCAN() do include a period, but you can specify the delimiters you want to use.

%let cutoff = 90 95 96 96.5;

%do i=1 %to %countw(&cutoff,%str( ));

    %let value=%scan(&cutoff,&i,%str( ));

    ...

%end;


View solution in original post

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16

Hi,

I have created a dummy dataset by using the macro variable with the values provided and it has created a dataset without any problem. Could you please check the below code and let me know if this is not the way you want to use it.

%let cutoff = 90 95 96 96.5;

%put &cutoff;

data have;

  array mac(4) (&cutoff);

  do i = 1 to 4;

  new=mac(i);

  output;

  end;

run;

Thanks,

Jag

Thanks,
Jag
Tom
Super User Tom
Super User

You will need to provide more about how you are using the values.

Perhaps you are using the %SCAN() function?  The default delimiters for %SCAN() do include a period, but you can specify the delimiters you want to use.

%let cutoff = 90 95 96 96.5;

%do i=1 %to %countw(&cutoff,%str( ));

    %let value=%scan(&cutoff,&i,%str( ));

    ...

%end;


EricCai
Calcite | Level 5

Ahh...yes, thank you, Tom.  I did not specify the delimiter when I used %SCAN().  Once I corrected that with %STR( ), the macro worked.

Thank you! 

And thank you, Jagadishkatam, for providing your sample code!

CFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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
  • 3 replies
  • 4696 views
  • 3 likes
  • 3 in conversation