Expanding data in SAS

Reply
N/A
Posts: 1

Expanding data in SAS

Hello, I am pretty new to SAS and was wondering if someone
could help me with the following:

I have sample data set as follows:

name start_week end_week
----- ---------- --------
andy 3 8
cindy 4 6
jess 1 5

and I want to create a data as follows from the above data set.

name week
---- ----
andy 3
andy 4
andy 5
andy 6
andy 7
andy 8
cindy 4
cindy 5
cindy 6
jess 1
jess 2
jess 3
jess 4
jess 5

Any ideas are greatly appreciated!

Thanks very much!
Kushi_Wije
SAS Employee
Posts: 1

Re: Expanding data in SAS

data work.start;
infile cards;
input name $1-8 start_week end_week ;
cards;
andy 3 8
cindy 4 6
jess 1 5
;
run;

data work.finish(rename=(start_week=week));
set work.start;
do while(start_week<=end_week);
output;
start_week+1;
end;
drop end_week;
run;
N/A
Posts: 0

Re: Expanding data in SAS

Or you could do this, which is easier to read (probably):

data work.finish(drop=start_week end_week);
set work.start;

do week=start_week to end_week;
output;
end;
run;
Contributor
Posts: 73

Re: Expanding data in SAS

you essentially want to transpose your data from horizontal to vertical. You can use Proc Transpose and ask it to transpose start & end week by name.
Ask a Question
Discussion stats
  • 3 replies
  • 390 views
  • 0 likes
  • 4 in conversation