Hi everyone,
My goal is to create a large data table that has descriptive statistics accompanying each observation. I am loading in a large file for which each observation has its own mean, standard deviation and percentiles. The variable that I am using to calculate all of this is named 'tapefile'. Basically what I am trying to do is create a large data table that neatly displays these statistics. I have been trying to accomplish this by saving the proc univariate command as a variable and then printing. I am new to sas so I am not entirely sure if this is even possible. Below is a sample of the data table that I seek to achieve.
Observation | Mean | Std Dev | 50th Percentile | 60th Percentile | 70th Percentile | 80th Percentile | 90th Percentile | 100th Percentile |
---|---|---|---|---|---|---|---|---|
1 | ||||||||
2 | ||||||||
3 | ||||||||
4 |
Here is a sample of my code as well:
options ls=176 ps=44;
libname master 'library location';
filename input0 'file location';
data detail;
infile input0 lrecl=605 recfm=f;
input (long list of ebcdic variables);
run;
proc sort data=detail;
by tapefile;
run;
proc univariate data=detail noprint;
var tapefile;
output out=res mean=mean pctlpts = 50 to 100 by 10 pctlpre=p;
run;
proc print data=detail label;
var tapefile tab_guca_mod_1 res;
label
p50="50th Percentile"
p60="60th Percentile"
p70="70th Percentile"
p80="80th Percentile"
p90="90th Percentile"
p100="100th Percentile";
run;
Thank you for any help you may be able to provide; I greatly appreciate it.
Assuming you're asking to add in the overall statistics rather than the statistics for "each observation has its own mean, standard deviation and percentiles".
You can calculate the stats in proc means and then merge then in using a SQL cross join.
proc means data=sashelp.class ;
var height;
output out=stats mean= std= p50= p60= p70= p80= p90= max=/autoname;
run;
proc sql;
create table class as
select *
from sashelp.class
cross join stats;
quit;
Are you trying to get the same set of percentiles attached to all values of tapefile? Or are you using TAPEFILE as shorthand to indicate you want to do the same thing to each variable in the (long list of ebcdic variables)? You might show some dummy output of what you expect your final table to look like.
Try this technique:
data detail ;
input tapefile larry more curly ;
cards ;
3 31 32 33
1 11 12 13
2 21 22 23
;
proc sort data=detail ;
by tapefile ;
run ;
proc transpose data=detail out=long ;
by tapefile ;
var larry more curly ;
run ;
proc univariate data=long noprint ;
by tapefile ;
output out=res mean=mean
pctlpts = 50 to 100 by 10 pctlpre=p ;
run ;
proc print data=res label ;
label
p50="50th Percentile"
p60="60th Percentile"
p70="70th Percentile"
p80="80th Percentile"
p90="90th Percentile"
p100="100th Percentile" ;
run ;
Torri92 wrote:
Hi everyone,
My goal is to create a large data table that has descriptive statistics accompanying each observation. I am loading in a large file for which each observation has its own mean, standard deviation and percentiles. The variable that I am using to calculate all of this is named 'tapefile'. Basically what I am trying to do is create a large data table that neatly displays these statistics. I have been trying to accomplish this by saving the proc univariate command as a variable and then printing. I am new to sas so I am not entirely sure if this is even possible. Below is a sample of the data table that I seek to achieve.
Observation | Mean | Std Dev | 50th Percentile | 60th Percentile | 70th Percentile | 80th Percentile | 90th Percentile | 100th Percentile |
---|---|---|---|---|---|---|---|---|
1 | ||||||||
2 | ||||||||
3 | ||||||||
4 |
Here is a sample of my code as well:
options ls=176 ps=44;
libname master 'library location';
filename input0 'file location';
data detail;
infile input0 lrecl=605 recfm=f;
input (long list of ebcdic variables);
run;
proc sort data=detail;
by tapefile;
run;
proc univariate data=detail noprint;
var tapefile;
output out=res mean=mean pctlpts = 50 to 100 by 10 pctlpre=p;
run;
proc print data=detail label;
var tapefile tab_guca_mod_1 res;
label
p50="50th Percentile"
p60="60th Percentile"
p70="70th Percentile"
p80="80th Percentile"
p90="90th Percentile"
p100="100th Percentile";
run;
Thank you for any help you may be able to provide; I greatly appreciate it.
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 how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.