Adding variables to SAS datasets - Multiple at a time

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 121
Accepted Solution

Adding variables to SAS datasets - Multiple at a time

The code below references the attached data set. I know that I can drop three variables and even more at a time from the array 'month' by simply changing the number of elements in me array. Is there a simpler way for me to also add three or more variables at a time, without having to write them out one after the other as I have done with month16, month17, and month18 below? All new variables added would have the same value.

        data hpi;

          set example;
             array month{15} month1-month15;

             drop month13-month15;
               month16=month15;

               month17=month15;

               month18=month15;
            run;

Attachment

Accepted Solutions
Solution
‎06-11-2014 11:40 AM
Super User
Posts: 10,500

Re: Adding variables to SAS datasets - Multiple at a time

data hpi; 

          set example;
             array month{15} month1-month18; /* if a variable doesn't already exist but is referenced when creating an array the variable will be created*/

             drop month13-month15;

          do _i_ = 16 to 18; month[_i_] = month15; end;
            run;

View solution in original post


All Replies
Solution
‎06-11-2014 11:40 AM
Super User
Posts: 10,500

Re: Adding variables to SAS datasets - Multiple at a time

data hpi; 

          set example;
             array month{15} month1-month18; /* if a variable doesn't already exist but is referenced when creating an array the variable will be created*/

             drop month13-month15;

          do _i_ = 16 to 18; month[_i_] = month15; end;
            run;

☑ This topic is SOLVED.

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

Discussion stats
  • 1 reply
  • 150 views
  • 0 likes
  • 2 in conversation