BookmarkSubscribeRSS Feed
Ruhi
Obsidian | Level 7

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;

 

4 REPLIES 4
ballardw
Super User

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

 

ballardw
Super User

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 921 views
  • 0 likes
  • 3 in conversation