BookmarkSubscribeRSS Feed
deleted_user
Not applicable
How do i extract the first record post grouping the observations in EG.

Thanks & would appreciate any help
Cheers
ALT
2 REPLIES 2
deleted_user
Not applicable
Hello Alt,

I'm not sure if this is what you're trying to do but getting the first observation of each By group can easily be done with SAS code:

proc sort data=sashelp.prdsale out=test;
by product;run;

data prdsale;
set test;
by product;
if first.product then output;
else delete;
run;

Is this what you're trying to do?
I'm not sure if there is a built in task that does this in EG but you could add this as a code node in your process flow or insert it as custom code in your task node.
Olivier
Pyrite | Level 9
If you agree to include some code in your EG project, the previous answer is the simplest you can do. If you want to stick to EG "point-and-click" way of life, I suggest the following...
Start a query on your data.
Compute 2 new variables :
1) one named "SEQUENCE" (for example) with the following formula : MONOTONIC()
2) one named "FIRST" with the following formula : MIN(CALCULATED sequence)
The SEQUENCE variable will consist in numbers given to each data line, in a sequential way (hence its name) : 1, 2, 3, ... The FIRST variable will compute the minimum sequence number for each group. Don't forget to add in the query interface that the FIRST variable is to be computed for each group !

One last thing : in the "Group Filtering" tab, add the condition that SEQUENCE = FIRST. And then you're done.
The SAS code produced should somehow look like this :

PROC SQL ;
SELECT *,
MONOTONIC() AS order,
MIN(CALCULATED order) AS first
FROM sashelp.class
GROUP BY age
HAVING order = first
;
QUIT ;

This gives you the first child for each group of Age, from the SASHELP.CLASS dataset.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2 replies
  • 6033 views
  • 0 likes
  • 2 in conversation