BookmarkSubscribeRSS Feed
rykwong
Quartz | Level 8

Dear SAS community

I was given this macro which is useful to use but it only runs it for var1.  I need to repeat this for all 600 variables (var1, var2, var3... ...var600) in a dataset.   Each of var1, var2....var600 is a column of data in the dataset.

 

My purpose of running this macro is to extract the name of the dependent variables, name of the variable (i.e. var1), and the P-value of the interaction term (drug*var1).  Is there a way to automate this?  Many thanks 

 

ods graphics / reset=all;

%macro loop;

data pv2_var1;

format y $20.;

run;

%let endpoint=d_lvef ln_lvesvi d_globalecvrem ln_ecv_rem d_total_lge_fw ln_total_lge_fw;

%do i=1 %to 6;

%let y=%scan(&endpoint,&i,' ');

title "Endpoint = &y";

ODS OUTPUT SOLUTIONF=RESULTS;

proc mixed data=testset covtest noclprint plots=studentpanel method=reml;

class patient_id site_id;

model0: model &y = drug var1 drug*var1/ s cl ddfm=kenwardroger;

run;

DATA pv2_var1;

SET pv2_var1 RESULTS(IN=A);

if missing(effect) then delete;

IF A THEN Y="&y";

RUN;

 

%end;

title " ";

%mend;

%loop

4 REPLIES 4
Astounding
PROC Star

What is it that you want to automate, that isn't already automated?  How to get a list of 600 variable names?  The rest looks pretty well automated except for one piece.  The final DATA step should be replaced with:

 

data results;

set results;

length y $ 32;

y = "&y";

if missing(effect) then delete;

run;

 

proc append data=results base=pv2_var1;

run;

rykwong
Quartz | Level 8

thanks.  I needed to run 600 variables, so instead of var1, run the macro with var2, then var3..... all the way to var600.  Note that var1, var2 ...etc are just names for the purpose of discussion, the variables have read names and they are not patterned.  There are also variable columns that are not a part of the 600 in between these 600 variables in the list (although I can remove them)

 

many thanks

 

Reeza
Super User

http://www.ats.ucla.edu/stat/sas/seminars/sas_macros_introduction/

 

If you make your macro more generic, to take a parameter that's the variable name then you can query the DICTIONARY.COLUMNS table to get a variable list. Then you can use CALL EXECUTE to execute the macro for each variable. 

rykwong
Quartz | Level 8

thanks so much.  this solves this issue.  Much appreciated!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 798 views
  • 0 likes
  • 3 in conversation