Hi
I have recently started using macro is sas and I am stuck at this issue. Please help!!
I want the covaraince estimates from proc mixed in sas for around 45 varaibles in my data set. I want to append the results in a final data set and I also want that the final dataset should tell me which varaince components belong to which varaible. So after proc mixed , I am creating a dataset named new to add those varaible name from the macro statement in the data.(VARNAME,and CAT). But actually when I run this macro and print the final results I should have three variance components from each iteration of macro, but actually it has way more than that. I don't understand what I am doing wrong. Please suggest some way out.
Thanks
%MACRO var(DATA, VARNAME,cat);
ods select none;
ods output covparms=Cov_Estimates;
proc mixed data=prep method=type1 cl;
class pt image scanwithinday ;
model &varname=;
random pt scanwithinday(pt);
run;
data new;
set new Cov_Estimates;
retain Vname Category;
call symput ('Vname','&varname' );
call symput ('Category','&cat');
run;
data final;
set final new ;run;
%mend;
data final;stop;
%var(data, varname=vp_dl,cat=Localisation and Distance);
%var(data,varname=vp_dr,cat=Localisation and Distance);
%var(data,varname=dl_dr,cat=Localisation and Distance);
ods select all;
proc print data=final;
run;
Did a dataset NEW or FINAL exist before running the code? Possibly left over from testing/development? If you didn't delete the sets then the previous data was still around and you added to it. That would be my guess for most likely cause.
I'm not sure what these lines are intended to accomplish:
call symput ('Vname','&varname' );
call symput ('Category','&cat');
But they will not result in what you likely intended as macro variables should be between double quotes to resolve to the assigned value:
call symput ('Vname',"&varname" );
call symput ('Category',"&cat");
I figured out my mistake. Thanks!!
Please post a description of the solution or error so others may benefit from your experience.
Why do you need a macro for that? You will be aware of by group processing, set your data up correctly and you could simply by group the whole dataset:
proc mixed data=prep method=type1 cl; by <group variables>; class pt image scanwithinday ; model <variable>=; random pt scanwithinday(pt); run;
Far simpler and more efficient.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.