06-02-2016 04:57 PM - edited 06-02-2016 04:58 PM
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.
%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;
06-02-2016 05:12 PM - edited 06-02-2016 05:15 PM
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");
06-03-2016 04:31 AM
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.