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.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.