DATA Step, Macro, Functions and more

creating a dataset

Accepted Solution Solved
Reply
Regular Contributor
Posts: 234
Accepted Solution

creating a dataset

Hello,

 

I have a data set below.  I want to increment the visit_num upto number_of_visits for each treatment.

 

Treatment  visit_num   number_of_visits

A                    101            2

B                    101            3

 

Desired dataset:

 

Treatment  visitnum  

A                    101  

A                    102        

B                    101

B                    102

B                    103      

 

Thank you !     

 

 


Accepted Solutions
Solution
‎06-19-2016 04:16 PM
Super User
Posts: 17,960

Re: creating a dataset

Use a do loop with an explicit output statement. 

 

Heres as a sample for you:

 


Data want;
Set have; Do I=1 to num_of_visits; Visit_num= Visit_num+I-1; OUTPUT; End;

run;

View solution in original post


All Replies
Solution
‎06-19-2016 04:16 PM
Super User
Posts: 17,960

Re: creating a dataset

Use a do loop with an explicit output statement. 

 

Heres as a sample for you:

 


Data want;
Set have; Do I=1 to num_of_visits; Visit_num= Visit_num+I-1; OUTPUT; End;

run;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 189 views
  • 1 like
  • 2 in conversation