Dear All,
I want to count the number of observations in each row that satisfiy a certain condition. I want o repreat this procedure for many data set so I'm using macro, but I have problem with using array inside marco. I attached a sample data set and the code I wrote.
Thank you in advance!!!
Best wishes.
data varselect1;
input variable1 variable2 variable3;
cards;
15 20 17
15 18 46
4 5 7
9 40 46
;
run;
%let J=3
%macro count;
%do j=1 %to &J;
data count&j;
set varselect&j;
array a{*} _numeric_;
lt15 = 0;
%do _n_=1 %to 3;
%if a{_n_} lt 15 %then lt15+1;
%end;
run;
%end;
%mend count;
%count
;
If you're in a data step don't use a macro do loop , use a data step do loop, ie no %
If you're in a data step don't use a macro do loop , use a data step do loop, ie no %
You're using the same macro variable twice, as a counter and loop end.
%let j=3;
%do j=1 %to &j
The macro DO loop creates a new macro J variable. I would definely expect unexpected behaviour with this type of coding. Using a different macro variable will help resolve this issue.
%let end_loop=3;
%do j=1 %to &end_loop
No, case only matters in working with character variables.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.