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!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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