BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
windy
Quartz | Level 8

Hi all, 

 

Please help me to solve this problem.

I want to run a macro to perform the transpose for many datasets. However, the number of variables that need to be transposed is slightly different across datasets. It could be 39, 40 or 41. Suppose I define those variables as VAR1, VAR2, etc. 

 

My macro for transpose is like:

%Macro transpose;

%do i=1999 %to 2018;

proc transpose data=have_&i out=want_&i;

var var1-var40;              /*the number of vars is different across each dataset (in each year)*/

run;

%end;

%mend transpose;

 

I created a dataset below to have the number of variables I need to transpose in each year:

data num_var;
input year num_var;
cards;
2018 40
2017 40
2016 40
2015 40
2014 39
2013 39
2012 39
2011 39
2010 40
2009 39
2008 39
2007 39
2006 41
2005 41
2004 40
2003 40
2002 40
2001 40
2000 39
1999 39
;
run;

 

For each dataset (in each year), how can I use the value in the dataset num_var to define the VAR option in my transpose macro?

 

Many thanks in advance. 

 

1 ACCEPTED SOLUTION
2 REPLIES 2

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 677 views
  • 1 like
  • 2 in conversation