I am using the code suggested in one of the answers as I want to get the first and last date of a country.
data get_first_and_last;
set master_table;
by ID Date;
if first.date or last.Date then output;
run;
However, I still get the dates in between and I'm replacint ID by country
I have the following observations
country date
countrya 01jan00
countrya 01feb00
countrya 01feb00
countrya 01mar00
etc ...
countrya 01nov11
How do I get only the country and 01jan00 and 01nov11? Is there any other way. I have a lot of observations and variables and I only choose the country and the date that is why I have repeated dates.
Thank you
data have;
informat date date7.;
format date date7.;
input country $ date;
cards;
countrya 01jan00
countrya 01feb00
countrya 01feb00
countrya 01mar00
countrya 01nov11
countryb 01jan00
countryb 01feb00
countryb 01feb00
countryb 01mar00
countryb 01nov11
;
proc sort; by country date;
data want;
set have;
by country;
if first.country or last.country;
run;
proc print; run;
Change two lines in your code:
by ID;
if first.ID or last.ID then output;
data have;
informat date date7.;
format date date7.;
input country $ date;
cards;
countrya 01jan00
countrya 01feb00
countrya 01feb00
countrya 01mar00
countrya 01nov11
countryb 01jan00
countryb 01feb00
countryb 01feb00
countryb 01mar00
countryb 01nov11
;
proc sort; by country date;
data want;
set have;
by country;
if first.country or last.country;
run;
proc print; run;
This is perfect! exactly what I needed.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.