data A;
input x y z id;
datalines;
1 2 3 1
4 5 6 1
7 8 9 2
4 8 7 2
1 4 7 2
4 8 9 3
;
run;
%macro filter(id);
data B_&id;
set A;
where id = &id;
run;
proc means data=B_&id noprint;
var x y z;
output out=new_&id(keep=_STAT_ x y z);
run;
%mend filter;
%filter(2);
Ok, you make a good point.
Run the analyses prior to OPTMODEL with a BY statement. Then
%macro do_this(ids);
%let num_ids=%sysfunc(countw(&ids));
%do i=1 %to &num_ids;
%let this_id=%scan(&ids,&i,%str( ));
proc optmodel;
read data whatever(where=(id=&this_id)) ...
/* Proc OPTMODEL Statements go here */
create data id_&this_id from ... ;
run;
%end;
%mend;
%do_this(1 8 9)
data A;
input x y z id;
datalines;
1 2 3 1
4 5 6 1
7 8 9 2
4 8 7 2
1 4 7 2
4 8 9 3
;
run;
%macro filter(id);
data B_&id;
set A;
where id = &id;
run;
proc means data=B_&id noprint;
var x y z;
output out=new_&id(keep=_STAT_ x y z);
run;
%mend filter;
%filter(2);
Use a BY statement in PROC MEANS. Do not use macros for this purpose.
proc sort data=a;
by id;
run;
proc means data=a noprint;
by id;
var x y z;
output out=new;
run;
If you only want IDs 1 8 and 9 in the analysis, then change the above to
proc means data=a(where=(id in (1,8,9))) noprint;
Hi Paige,
Thanks for the answer!
But, I will use it for several others procs too, some of then do not allow the by statement, so it's not a possibility.
Regards,
Alana.
Almost every SAS PROC that does data analysis has a BY statement (and DATA steps have BY statements too).
So which data analysis PROC are you looking at that does not allow a BY statement?
PROC optmodel
Regards,
Alana.
Ok, you make a good point.
Run the analyses prior to OPTMODEL with a BY statement. Then
%macro do_this(ids);
%let num_ids=%sysfunc(countw(&ids));
%do i=1 %to &num_ids;
%let this_id=%scan(&ids,&i,%str( ));
proc optmodel;
read data whatever(where=(id=&this_id)) ...
/* Proc OPTMODEL Statements go here */
create data id_&this_id from ... ;
run;
%end;
%mend;
%do_this(1 8 9)
Thanks Paige!
It works!
Best regards,
Alana.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.