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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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
  • 2 replies
  • 591 views
  • 1 like
  • 2 in conversation