Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>proc sort data=sampleData out=sampleData_s; by payee_id amt_billed; run; </code></pre> <p>You can use descending if by 'top' you mean largest e.g. <code>by payee_id descending amt_billed;</code></p> <p>Once the data are sorted you are able to read into a data step and use <code>first</code> and <code>last</code> e.g.</p> <pre><code>data partial_solution(drop=count); retain count 0; set sampleData_s; by payee_id descending amt_billed; if first.payee_id then count=0; count+1; if count le 3 then output; run; </code></pre> <p>To output to different dataset names:</p> <pre><code>proc sort data=sampleData(keep=payee_id) out=all_payee_ids nodupkey; by payee_id; run; data _null_; length id_list $10000; * needs to be long enough to contain all ids; * if you do not state this, sas will default; * length to first value; retain id_list; set all_payee_ids end=eof; id_list = catx('|', id_list, payee_id); if eof then call symputx('macroVarIdList', id_list); run; </code></pre> <p>You've now got a pipe separated list of all your id's. You can loop through these using them to create names for you datasets. You need to do this as SAS needs to know the names of the datasets you want to output to up front e.g.</p> <pre><code>data ds1 ds2 ds3 ds4; set some_guff; if blah then output ds1; else if blahblah then output ds2; else output d3; output d4; run; </code></pre> <p>So with the macro var loop:</p> <pre><code>%let nrVars=%sysfunc(countw(&amp;macroVarIdList)); data %do i = 1 %to &amp;nrVars; dataset_%scan(&amp;macroVarIdList,&amp;i,|) %end; ; set partial_solution; count+1; %do j = 1 %to &amp;nrVars; %let thisPayeeId=%scan(&amp;macroVarIdList,&amp;j,|); if payee_id = "&amp;thisPayeeId" then output dataset_&amp;thisPayeeId.; %end; run; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload