creation of new variable

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 96
Accepted Solution

creation of new variable


I am trying to create a variable from the following dataset.

Company  year   OUT

A               2001     0    

A               2002     0              
A               2003     0              
A               2004     1              
A               2005     0              
A               2006     0              
A               2007     0              
A               2008     0              
B               2000     0              
B               2001     0              
B               2002     0              
B               2003     1              

B               2004     0             

B               2005     0              

B               2006     0              

B               2007     0              

B               2008     0             

B               2009     0              

I want to create a new variable NEW for all firm-observations where OUT =1 and year less than 2009.

Company  year   OUT     NEW

A               2001     0          1

A               2002     0          1              
A               2003     0          1              
A               2004     1          1  
A               2005     0          1              
A               2006     0          1              
A               2007     0          1              
A               2008     0          1              
B               2000     0          0              
B               2001     0          0              
B               2002     0          0              
B               2003     1          0              

B               2004     0          0             

B               2005     0          0              

B               2006     0          0              

B               2007     0          0              

B               2008     0          0             

B               2009     0          0  

Any suggession will be helpful.


Accepted Solutions
Solution
‎09-02-2012 08:04 PM
Respected Advisor
Posts: 4,659

Re: creation of new variable

Simpler this time, if I understand your request correctly :

data have;
input Company $ year OUT;
datalines;
A               2001                    0         
A               2002                    0         
A               2003                    0         
A               2004                    1         
A               2005                    0         
A               2006                    0         
A               2007                    0         
A               2008                    0         
B               2000                    0         
B               2001                    0         
B               2002                    0         
B               2003                    1         
B               2004                    0         
B               2005                    0         
B               2006                    0         
B               2007                    0         
B               2008                    0         
B               2009                    0         
;

proc sql;


create table want as
select *, max(OUT) > 0 and max(year) < 2009 as NEW
from have
group by company
order by company, year;


select * from want;
quit;

PG

PG

View solution in original post


All Replies
Solution
‎09-02-2012 08:04 PM
Respected Advisor
Posts: 4,659

Re: creation of new variable

Simpler this time, if I understand your request correctly :

data have;
input Company $ year OUT;
datalines;
A               2001                    0         
A               2002                    0         
A               2003                    0         
A               2004                    1         
A               2005                    0         
A               2006                    0         
A               2007                    0         
A               2008                    0         
B               2000                    0         
B               2001                    0         
B               2002                    0         
B               2003                    1         
B               2004                    0         
B               2005                    0         
B               2006                    0         
B               2007                    0         
B               2008                    0         
B               2009                    0         
;

proc sql;


create table want as
select *, max(OUT) > 0 and max(year) < 2009 as NEW
from have
group by company
order by company, year;


select * from want;
quit;

PG

PG
Frequent Contributor
Posts: 96

Re: creation of new variable


Thanks PGstats for the prompt solution.

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 219 views
  • 0 likes
  • 2 in conversation