BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
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)*/



%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;
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


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. 





Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg



Back in the Classroom!

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

View all other training opportunities.

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