DATA Step, Macro, Functions and more

Sas macro, Results from multiple runs of macro should append in one dataset , but its not, why??

Reply
Contributor
Posts: 39

Sas macro, Results from multiple runs of macro should append in one dataset , but its not, why??

[ Edited ]

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;

 

Super User
Posts: 11,343

Re: Sas macro, Results from multiple runs of macro should append in one dataset , but its not, why??

[ Edited ]

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");

 

Contributor
Posts: 39

Re: Sas macro, Results from multiple runs of macro should append in one dataset , but its not, why??

I figured out my mistake. Thanks!!

Super User
Posts: 11,343

Re: Sas macro, Results from multiple runs of macro should append in one dataset , but its not, why??

Please post a description of the solution or error so others may benefit from your experience.

Super User
Super User
Posts: 7,942

Re: Sas macro, Results from multiple runs of macro should append in one dataset , but its not, why??

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.

 

Ask a Question
Discussion stats
  • 4 replies
  • 255 views
  • 0 likes
  • 3 in conversation