Help using Base SAS procedures

how avoiding proc sorting before proc transpose

Accepted Solution Solved
Reply
Super Contributor
Posts: 301
Accepted Solution

how avoiding proc sorting before proc transpose


Hi everyone,

in terms of avoiding the sorting step before transpose it, if you cehck my code, it look like that using proc freq (commented) or proc summary, the proc sorting is neccesary:

any suggestion to avoid it (not proc sql, please), or if not, an explanation of why not?

Thanks. V

    proc sort data= old1 nodupkey;
    by subjid randtext soc;
    run;


    /*proc freq data=old1 noprint;
    tables randtext*soc/out=fold1 (drop=percent);
    run;*/


   proc summary data=old1 nway;
   class randtext soc/missing;
   output out=probe (drop=_type_);
   run;

  * is always this proc sorting neccesary before the proc transpose by soc?;

    proc sort data=probe out=sprobe
    by  soc;
    run;

    proc transpose data=sprobe out=tprobe;
    by soc;
    id randtext;
    var _freq_;
    run;


Accepted Solutions
Solution
‎06-19-2012 09:32 AM
Respected Advisor
Posts: 3,799

Re: how avoiding proc sorting before proc transpose

If you change the order of the variables in PROC SUMMARY CLASS statement from

class randtext soc/missing;

to 
class SOC randtext / missing;

You can remove the PROC SORT step.

The data output from PROC SUMMARY are "SORTED" by _TYPE_ and class variables.  Similar to BY _TYPE_ SOC RANDTEXT;

Since you use NWAY you only have one _TYPE_ you can ignore it.

View solution in original post


All Replies
Solution
‎06-19-2012 09:32 AM
Respected Advisor
Posts: 3,799

Re: how avoiding proc sorting before proc transpose

If you change the order of the variables in PROC SUMMARY CLASS statement from

class randtext soc/missing;

to 
class SOC randtext / missing;

You can remove the PROC SORT step.

The data output from PROC SUMMARY are "SORTED" by _TYPE_ and class variables.  Similar to BY _TYPE_ SOC RANDTEXT;

Since you use NWAY you only have one _TYPE_ you can ignore it.

Super Contributor
Posts: 301

Re: how avoiding proc sorting before proc transpose

Posted in reply to data_null__


Briiliant, Thanks.

Frequent Contributor
Posts: 95

Re: how avoiding proc sorting before proc transpose

If you modify your code as follows you won't need proc sort after step proc summary as proc summary generates sorted output by class variables.

I don't have data to test it but give it a try.

proc summary data=old1 nway;

   class soc randtext/missing;

   output out=probe (drop=_type_);

   run;

   

    proc transpose data=probe out=tprobe;
    by soc;
    id randtext;
    var _freq_;
    run;

Super Contributor
Posts: 301

Re: how avoiding proc sorting before proc transpose


Brilliant, Thanks.

🔒 This topic is solved and locked.

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

Discussion stats
  • 4 replies
  • 447 views
  • 3 likes
  • 3 in conversation