DATA Step, Macro, Functions and more

Assigning unique ID to a subset of observations

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Assigning unique ID to a subset of observations

I have a panel data with 1002 observations. N=334, T=3. My goal is to create 2 columns representing N and the year T. For example, the first 334 observations will have ID from 1 to 334 and a fixed value of T=1. The next set will have observations from 335 to 668 and T=2. I tried this piece of code but it did not work. 

 

DATA WAGE;
SET WAGE(first_obs = 2)(obs = 335);
retain Person_ID = 1;
retain Year_ID = 1;
Person_ID + 1;
RUN;


Accepted Solutions
Solution
‎03-30-2018 11:24 PM
Esteemed Advisor
Posts: 5,626

Re: Assigning unique ID to a subset of observations

Posted in reply to adityal2810

Could be as basic as:

 

data want;
do T = 1 to 3;
    do ID = 1 to 334;
        set WAGE;
        output;
        end;
    end;
run;
PG

View solution in original post


All Replies
Solution
‎03-30-2018 11:24 PM
Esteemed Advisor
Posts: 5,626

Re: Assigning unique ID to a subset of observations

Posted in reply to adityal2810

Could be as basic as:

 

data want;
do T = 1 to 3;
    do ID = 1 to 334;
        set WAGE;
        output;
        end;
    end;
run;
PG
Super User
Posts: 13,942

Re: Assigning unique ID to a subset of observations

Posted in reply to adityal2810

Perhaps:

 

data want;
   set wage;
   id=_n_;
   t = floor((_n_-1)/334)+1;
run;
☑ This topic is solved.

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

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