SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Selecting the last var1 from each distinct var2

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 89
Accepted Solution

Selecting the last var1 from each distinct var2

I need to create a data set that list the last dekning_sk for each distinct avtale_sk from the following source data set:

So, the output data set should say:

Avtale_skDekning_sk
1145
3122
4145
6122
9122
12118
13167
15167

etc...

What kind of user written code would produce this kind of result? Either DATA STEP or PROC SQL would be fine.

Thanks for your time.


Accepted Solutions
Solution
‎10-08-2012 07:49 AM
Super Contributor
Posts: 1,636

Re: Selecting the last var1 from each distinct var2

Posted in reply to TurnTheBacon

How did you get 121 when avtale_sk=3 ? why not 122?

try the modified one:

data want;

  set have;

   by avtale_sk notsorted;

   if last.avtale_sk;

run;

View solution in original post


All Replies
Super Contributor
Posts: 1,636

Re: Selecting the last var1 from each distinct var2

Posted in reply to TurnTheBacon

try:

data want;

  set have;

   by avtale_sk dekning_sk notsorted;

   if last.dekning_sk;

run;

Frequent Contributor
Posts: 89

Re: Selecting the last var1 from each distinct var2

Thanks for the suggestion, but as far as I can tell the output data set looks exactly the same.

Solution
‎10-08-2012 07:49 AM
Super Contributor
Posts: 1,636

Re: Selecting the last var1 from each distinct var2

Posted in reply to TurnTheBacon

How did you get 121 when avtale_sk=3 ? why not 122?

try the modified one:

data want;

  set have;

   by avtale_sk notsorted;

   if last.avtale_sk;

run;

Frequent Contributor
Posts: 89

Re: Selecting the last var1 from each distinct var2

I'm very sorry, that was a typo. I should have been more vigilant. It's been corrected now.

Frequent Contributor
Posts: 89

Re: Selecting the last var1 from each distinct var2

Perfect, thank you very much Linlin. Smiley Happy

🔒 This topic is solved and locked.

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

Discussion stats
  • 5 replies
  • 230 views
  • 0 likes
  • 2 in conversation