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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.