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;
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.
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.
Briiliant, Thanks.
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;
Brilliant, Thanks.
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.