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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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