Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating data lines in SAS 1

Status
Not open for further replies.

kushiwije

Technical User
Jun 13, 2006
8
US
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

 
Two words - Do Loops! Set up a "do for" loop and use the two numbers as your start and end point.
something like this
Code:
data dset2(keep=name num);
  set dset1;

  do for i = start_week to end_week;
     week = i;
     i+1;
     output;
  end;
run;
I've not checked the syntax of this, I know several languages which have different syntaxes for the do for loop structure, so you'll need to look it up in the SAS doco to confirm that I've set it up correctly.
 
Thank you very much, Chris. I removed the 'for' and it worked just fine. Thanks again for the prompt response. Appreciate it!
 
Thank you very much, Chris. I removed the 'for' and it worked just fine. Thanks again for the prompt response. Appreciate it!

Kushi_Wije
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top