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
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.
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
DATA HAVE;
INPUT Id Startdate DDMMYY8. Enddate DDMMYY8.;
DATALINES;
1 15021994 06111994
2 15021995 31121995
2 01051996 .
;
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
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.
This should work:
DATA HAVE;
INPUT Id Startdate Enddate DDMMYY8.;
DATALINES;
1 15021994 06111994
2 15021995 31121995
2 01051996 .
;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.