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

Hi all,

My observations have FOUR variables: ID, DATE, year1 and year2. I want to create times series(frequency: yearly) data between year1 and year2.

I have already use proc transpose to create a variable YEAR which has year1 and year2 for each observation.

for example for observation A, if year1=1995 and year2=2006, then after the proc transpose I will have two observations A1 with YEAR=1995 and A2 with YEAR=2006.

Then I want to create all the time series observations with YEAR between 1995 and 2006. Namely, Year=1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005.


I tried to use proc expand to solve the problem(I did so with monthly data), but the code below does not work:#

proc expand data=mysample out=mysample1 From=year to=year;

by ID Date;

id YEAR;

convert YEAR;

run;

The code does not work. Is it because I should not use Proc expand or is there something wrong with the code? Or could anyone tell how to solve the problem?

Many thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

Seems like you need at least one "analysis" variable.  Without Y PROC EXPAND says "Nothing to do";

data test;
   do id = 1;
     
do year=1995,2006;
         year = mdy(
1,1,year);
         y=ranuni(1);
         output;
        
end;
     
end;
  
format year date.;
  
run;
proc expand data=test out=new method=none to=year;
   by id;
   id year;
   run;
proc print;
  
run;

View solution in original post

2 REPLIES 2
data_null__
Jade | Level 19

Seems like you need at least one "analysis" variable.  Without Y PROC EXPAND says "Nothing to do";

data test;
   do id = 1;
     
do year=1995,2006;
         year = mdy(
1,1,year);
         y=ranuni(1);
         output;
        
end;
     
end;
  
format year date.;
  
run;
proc expand data=test out=new method=none to=year;
   by id;
   id year;
   run;
proc print;
  
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!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1538 views
  • 1 like
  • 3 in conversation