BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Li2024
Fluorite | Level 6

Hi The original code is below and I tried to make these code to a macro:

data work.split_data;
array a[2] _temporary_ (0.5,0.5);
array b[2] $ _temporary_ ('train','validation')

;
set combine_data;
run;

 

The macro I made is below and I keep getting errors. Can anyone help?

 

%macro data_split(dataset,probs,labels);
data work.split_data;
array a[2] _temporary_ &prob;
array b[2] $ _temporary_ &labels;
set &dataset;
run;
%mend;


%data_split(work.combine_data,probs=(0.5, 0.5),labels=("a", "b"));

 

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

When you're asking a question about an error message, please include the error message in your question.

 

Assuming you get the error I get:

1       data work.split_data; array a[2] _temporary_ &prob; array b[2] $ _temporary_ &labels; set &dataset; run;
                                                     -
                                                     22
                                                     200
WARNING: Apparent symbolic reference PROB not resolved.

ERROR 22-322: Syntax error, expecting one of the following: (, ;.

ERROR 200-322: The symbol is not recognized and will be ignored.

Then the problem is a typo in your code.  Your array statement references a macro variable named PROB but it should reference PROBS:

array a[2] _temporary_ &prob;  *Missing an S on &probS;

 

The Boston Area SAS Users Group is hosting free webinars!
Next up: Lisa Mendez & Richann Watson present Get Tipsy with Debugging Tips for SAS® Code: The After Party on Wednesday Jul 16.
Register now at https://www.basug.org/events.

View solution in original post

4 REPLIES 4
Quentin
Super User

When you're asking a question about an error message, please include the error message in your question.

 

Assuming you get the error I get:

1       data work.split_data; array a[2] _temporary_ &prob; array b[2] $ _temporary_ &labels; set &dataset; run;
                                                     -
                                                     22
                                                     200
WARNING: Apparent symbolic reference PROB not resolved.

ERROR 22-322: Syntax error, expecting one of the following: (, ;.

ERROR 200-322: The symbol is not recognized and will be ignored.

Then the problem is a typo in your code.  Your array statement references a macro variable named PROB but it should reference PROBS:

array a[2] _temporary_ &prob;  *Missing an S on &probS;

 

The Boston Area SAS Users Group is hosting free webinars!
Next up: Lisa Mendez & Richann Watson present Get Tipsy with Debugging Tips for SAS® Code: The After Party on Wednesday Jul 16.
Register now at https://www.basug.org/events.
Li2024
Fluorite | Level 6

Thanks, I made a really stupid mistake. ....

Tom
Super User Tom
Super User

Assuming by "brackets" you mean normal parentheses then they are actually HELPFUL when passing values into macro parameters because they allow you to include commas in the values without the macro processor interpreting the commas as delimiters between parameter values.

 

So your code works fine (once you fix the typo in the macro variable name and adjust the LENGTH of the character values stored in the second array).

array a[2] _temporary_ &probs;
array b[2] $255 _temporary_ &labels;

Another useful thing to understand is that SAS does NOT need the commas in those lists of values, spaces work fine.  

array a[2] _temporary_ (0.5 0.5);
array b[2] $200 _temporary_ ('train' 'validation');

The same thing applies to lists of values in other places, like the IN operator.

 

So you could remove the parentheses from your macro call and instead have the macro insert them.  Then call the macro using spaces between the values in the lists.  

%macro data_split(dataset,probs,labels);
data split_data;
  array a[2] _temporary_ (&probs);
  array b[2] $255 _temporary_ (&labels);
  set &dataset;
  * some code that actually uses A and B ;
run;
%mend;
%data_split(work.combine_data,probs=0.5 0.5,labels="a" "b")

 You can include the parentheses in the macro call still since the ARRAY statement does not mind if you add extra nested pairs.  Example:

67   data test;
68     array x[4] ((1 2) (3 4));
69     put _all_;
70   run;

x1=1 x2=2 x3=3 x4=4 _ERROR_=0 _N_=1
Li2024
Fluorite | Level 6

Thanks, I made really stupid mistake.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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