Hi Ksharp,
how can i prevent producing the first row of each Regoin using Proc Report.
The SAS System | ||||
Region | AgentID | Sales | Number | _BREAK_ |
of Agents | ||||
E | . | 99 | 0 | Region |
E | 1 | 38 | 0 | |
E | 2 | 29 | 1 | |
E | 3 | 32 | 2 | |
E | . | 99 | 3 | Region |
N | . | 88 | 3 | Region |
N | 4 | 76 | 0 | |
N | 5 | 12 | 1 | |
N | . | 88 | 2 | Region |
S | . | 49 | 2 | Region |
S | 7 | 25 | 0 | |
S | 8 | 24 | 1 | |
S | . | 49 | 2 | Region |
W | . | 27 | 2 | Region |
W | 9 | 27 | 0 | |
W | . | 27 | 1 | Region |
I don't understand what you mean exactly --- 'the first row of each Regoin ' ?
You want delete obs which are the first obs in each region group in TEMP dataset ? That is easy.
data x;
set temp;
if region ne lag(region) then delete;
run;
Ksharp
Hi Ksharp,
Thank you for your code.
Yes. we can use one more data step to get rid of the first row.
My interested is if there is any statement or option in REPORT procendure can do that?
to me, i only need the last row of each region which show me the total sales and unique agent.
so my question could be if there is any way to create the temp data show the last row of each region only?
Thanks
E | . | 99 | 0 | Region |
E | . | 99 | 3 | Region |
That is easy. Just add a filter condition on the TEMP dataset.
proc report data = test nowd out=temp(where=(agentid is missing));
But I prefer to use SQL.
proc sql;
create table want as
select region,sum(sales) as sum_sales,count(distinct agentid) as NumofAgentId
from test
group by region;
quit;
Ksharp
Hi Ksharp,
As we known, we can summarizing data using group by wtih cube / rollup in SQL server.
i dont think SAS proc sql has this option.
i am alway struggling with decision of using proc mean/report/tabulate or proc sql for summarizing data.
with your great SAS programming experince, what's your thoughts and recommendation.
Thanks,
Well, I would firstly choose SQL way, which is more fast and more flexible and more succinct .Sure of course, If you want some special statistical estimator ,I will use proc means, SQL has some limitation about yielding these special statistical estimator . and I will use proc report / tabulate if you want some beautiful report or PDF/HTML .
Ksharp
Thanks Ksharp
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.