BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
coba
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

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;

View solution in original post

3 REPLIES 3
art297
Opal | Level 21

Change two lines in your code:

  by ID;

  if first.ID or last.ID then output;


Linlin
Lapis Lazuli | Level 10

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;

coba
Calcite | Level 5

This is perfect! exactly what I needed.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

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.

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
  • 3 replies
  • 3210 views
  • 0 likes
  • 3 in conversation