BookmarkSubscribeRSS Feed
terjeph
Obsidian | Level 7

I want to create a panel data based on a cross section data set and fill in observations per quarter. A variable Present needs to be created. Presents=1 if in the interval between Startdate and Enddate, 0 otherwise. The observation period starts 1 Jan 1994 and end 31 Dec 2015.

 

Have:

Id Startdate      Enddate

1 15021994     06111994

2 15021995     31121995

2 01011996     

3 01041998    01111998

 

Want:

Id YYQ       Present

1 1994Q1  1

1 1994Q2  1

1 1994Q3  1

1 1994Q4  0

1 1995Q1  0

1 1995Q2 0

       and so on until 2015Q4

2 1994Q1 0

2 1994Q2 0

2 1994Q3 0

2 1994Q4 0

2 1995Q1 1

2 1995Q2 1

2 1995Q3 1

2 1995Q4 1

2 1996Q1 0

2 1996Q2 0

2 1996Q3 0

2 1996Q4 1

2 1997Q1 1

          and so on until 2015Q4

 

     

 

8 REPLIES 8
andreas_lds
Jade | Level 19

Please provide data in usable form.

It is not clear how the missing value in the third obs should be processed.

And what about the observation period you have in the description? The Variable "YYQ" in want is way out of period you mention.

terjeph
Obsidian | Level 7

I want to create a panel data based on a cross section data set and fill in observations per quarter. A variable called Present needs to be created. Present = 1 for the interval between (and included) Startdate and (included) Enddate, 0 otherwise. The observation period starts 1 Jan 1994 and ends 31 Dec 1996. The missing value in dataline 3 indicate that the state is still ongoing (truncation).

 

DATA HAVE;
INPUT Id Startdate DDMMYYYY8. Enddate DDMMYYYY8.;
DATALINES;
1 15021994 06111994
2 15021995 31121995
2 01051996        .
;
DATA WANT;
ID yearqarter PRESENT
1 1994Q1  1
1 1994Q2  1
1 1994Q3  1
1 1994Q4  0
1 1995Q1  0
1 1995Q2 0
1 1995Q3 0
1 1995Q4 0
1 1996Q1  0
1 1996Q2 0
1 1996Q3 0
1 1996Q4 0
2 1994Q1 0
2 1994Q2 0
2 1994Q3 0
2 1994Q4 0
2 1995Q1 1
2 1995Q2 1
2 1995Q3 1
2 1995Q4 1
2 1996Q1 0
2 1996Q2 1
2 1996Q3 1
2 1996Q4 1

       

 

terjeph
Obsidian | Level 7

DATA HAVE;
INPUT Id Startdate DDMMYY8. Enddate DDMMYY8.;
DATALINES;
1 15021994 06111994
2 15021995 31121995
2 01051996 .
;

andreas_lds
Jade | Level 19

Please check the code prior to posting!


@terjeph wrote:
DATA HAVE;
INPUT Id Startdate DDMMYYYY8. Enddate DDMMYYYY8.;
DATALINES;
1 15021994 06111994
2 15021995 31121995
2 01051996
;

Log:

 69         DATA HAVE;
 70         INPUT Id Startdate DDMMYYYY8. Enddate DDMMYYYY8.;
                               __________         __________
                               485                485
 NOTE 485-185: Informat DDMMYYYY was not found or could not be loaded.
 
 71         DATALINES;
 
 NOTE: LOST CARD.
 REGEL:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0                     
 75         ;
 Id=2 Startdate=1051996 Enddate=. _ERROR_=1 _N_=3
 NOTE: SAS went to a new line when INPUT statement reached past the end of a line.
 NOTE: The data set WORK.HAVE has 2 observations and 3 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.07 seconds
       cpu time            0.01 seconds
andreas_lds
Jade | Level 19

I still get an unexpected note:

 69         data have;
 70            input Id Startdate DDMMYYn8. Enddate DDMMYYn8.;
                                  _________         _________
                                  485               485
 NOTE 485-185: Informat DDMMYYN was not found or could not be loaded.
terjeph
Obsidian | Level 7
Delete the n before 8
terjeph
Obsidian | Level 7

This should work:

 

DATA HAVE;
INPUT Id Startdate Enddate DDMMYY8.;
DATALINES;
1 15021994 06111994
2 15021995 31121995
2 01051996 .
;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1355 views
  • 0 likes
  • 2 in conversation