BookmarkSubscribeRSS Feed
ilikesas
Barite | Level 11

Hi,

 

I have a data table with many variables, and I want to do a proc ttest on these variables using a macro. Here is what I did:

 

1) First I did proc contents to extract the names of the variables and then putting them into a macro list:

 

proc contents data=mydata out=contents noprint;
run;

data contents;
set contents;
keep name;
run;

proc sql noprint;
 select name 
 into :name separated by ' '
 from contents;
 quit;

and then I wrote a macro that will do a proc ttest for all the varibales that are in the macro list "name":

 

%macro means;

%do %while("&name" NE "");

proc ttest data=mydata ;
      class developed;
	  var  &name;
   run;

%mend;

%means;


But the macro runs without stopping...

I therefore guess that the code has an error somewhere, but the intuition behind the code is that the macro should run for all the variables within the macro list "name" and stop when there are no more variables left.

 

Thanks!

1 REPLY 1
Reeza
Super User

You never extract the variables from the list, you pass the list directly to PROC TTEST.

Additionally, you never change the macro variable so it's always the same, which is a list of variables, so never empty and your loop never ends.

 

Also, I don't think you need the loop or the macro list.

 

Try either not including a VAR statement at all, I suspect the default is to run it for all numeric variables. Or try the following:

 

proc ttest data=mydata;

class developed;

var _numeric_;

run;

 

 

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
  • 1 reply
  • 974 views
  • 1 like
  • 2 in conversation