BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
michtka
Fluorite | Level 6


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;

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

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

4 REPLIES 4
data_null__
Jade | Level 19

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.

michtka
Fluorite | Level 6


Briiliant, Thanks.

Alpay
Fluorite | Level 6

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;

michtka
Fluorite | Level 6


Brilliant, Thanks.

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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